Skip to content

Commit 051ae82

Browse files
committed
Update sourceEntity when copying parent association mappings
When ORMMappedSuperClassSubscriber copies association mappings from a parent mapped-superclass to a child entity, it must update the sourceEntity to point to the concrete child class. Without this, Doctrine's BasicEntityPersister generates incorrect SQL table aliases for eager-loaded inverse one-to-one associations, because the alias cache key uses the mapped-superclass name instead of the concrete entity name. This mirrors what Doctrine's own ClassMetadataFactory::addInheritedRelations() does when processing inheritance.
1 parent f067e01 commit 051ae82

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

src/Bundle/EventListener/ORMMappedSuperClassSubscriber.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ private function setAssociationMappings(ClassMetadata $metadata, Configuration $
8787
foreach ($parentMetadata->getAssociationMappings() as $key => $value) {
8888
$type = \is_array($value) ? $value['type'] : $value->type();
8989
if ($this->isRelation($type) && !isset($metadata->associationMappings[$key])) {
90+
if (\is_array($value)) {
91+
$value['sourceEntity'] = $class;
92+
} else {
93+
/** @psalm-suppress UndefinedClass */
94+
$value->sourceEntity = $class; /** @phpstan-ignore-line */
95+
}
96+
9097
$metadata->associationMappings[$key] = $value; /** @phpstan-ignore-line */
9198
}
9299
}

0 commit comments

Comments
 (0)