[make:entity] Generate a strict setter for non-nullable unidirectional ManyToOne relations#1797
Open
Amoifr wants to merge 1 commit into
Open
[make:entity] Generate a strict setter for non-nullable unidirectional ManyToOne relations#1797Amoifr wants to merge 1 commit into
Amoifr wants to merge 1 commit into
Conversation
…l ManyToOne relations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Concrete design proposal for #198, which reports that generated
ManyToOnesetters acceptnulleven when the relation is non-nullable (setCategory(?Category $category)for anullable: falseassociation).The discussion stalled on a real constraint: the setter must stay nullable for bidirectional relations, because the collection
remove*()generated on the inverse side sets the owning side back to null ($item->setOwner(null), orphanRemoval) — making everyManyToOnesetter strict would break that generated code.This PR tightens only the provably-safe subset: a non-nullable, unidirectional
ManyToOne, which has no suchremove*()null path:Bidirectional and explicitly-nullable relations are unchanged. This mirrors what already happens for non-nullable OneToOne setters (
$relation->isNullable()), just extended to theManyToOnecase that is provably safe.Scope / open questions
?Category $category = null— consistent with the current OneToOne behavior, and it avoids uninitialized-typed-property pitfalls with Forms.doctrine.associationType) is a bigger discussion — it reopens @javiereguiluz's Forms concern about uninitialized properties — so it's left out here. Happy to follow up if you'd like to go there.No existing fixtures change (no current test case is non-nullable + unidirectional); a new
many_to_one_not_nullable_no_inversecase + fixture covers it.