Fix check for composite foreign key#12285
Merged
greg0ire merged 1 commit intodoctrine:2.20.xfrom Nov 21, 2025
Merged
Conversation
HypeMC
commented
Nov 21, 2025
Comment on lines
-3176
to
+3183
| $isIteration = isset($hints[Query::HINT_INTERNAL_ITERATION]) && $hints[Query::HINT_INTERNAL_ITERATION]; | ||
| $isForeignKeyComposite = $targetClass->hasAssociation($assoc['mappedBy']) && count($targetClass->getAssociationMapping($assoc['mappedBy'])['joinColumns'] ?? []) > 1; | ||
|
|
||
| if ($assoc['type'] === ClassMetadata::ONE_TO_MANY && ! $isIteration && ! $isForeignKeyComposite && ! isset($assoc['indexBy'])) { | ||
| if ( | ||
| $assoc['type'] === ClassMetadata::ONE_TO_MANY | ||
| // is iteration | ||
| && ! (isset($hints[Query::HINT_INTERNAL_ITERATION]) && $hints[Query::HINT_INTERNAL_ITERATION]) | ||
| // is foreign key composite | ||
| && ! ($targetClass->hasAssociation($assoc['mappedBy']) && count($targetClass->getAssociationMapping($assoc['mappedBy'])['joinColumns'] ?? []) > 1) | ||
| && ! isset($assoc['indexBy']) | ||
| ) { |
Contributor
Author
There was a problem hiding this comment.
@greg0ire If I'm not mistaken, mappedBy should always be present for one-to-many associations.
I also inlined the conditions to avoid checking the same thing twice or making unnecessary method calls. If you think this is unnecessary, I can revert it.
Member
There was a problem hiding this comment.
Comments over one-time variables 👍
Brajk19
approved these changes
Nov 21, 2025
greg0ire
approved these changes
Nov 21, 2025
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.
Fixes #12282