Skip to content

Conversation

@HypeMC
Copy link
Contributor

@HypeMC HypeMC commented Nov 21, 2025

Fixes #12282

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'])
) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense to me 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments over one-time variables 👍

@greg0ire greg0ire added the Bug label Nov 21, 2025
@greg0ire greg0ire merged commit 15537bc into doctrine:2.20.x Nov 21, 2025
91 checks passed
@greg0ire greg0ire added this to the 2.20.9 milestone Nov 21, 2025
@HypeMC HypeMC deleted the fix-is-foreign-key-composite branch November 21, 2025 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants