From 0408e703d76a2378f1796259d282887b311d5ab7 Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Sat, 14 Jan 2023 23:56:42 +0000 Subject: [PATCH] Reword the actual fix --- lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index 8a85b19853c..2b9be227a28 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -381,10 +381,6 @@ private function addInheritedRelations(ClassMetadata $subClass, ClassMetadata $p if ($mapping['type'] & ClassMetadata::TO_MANY && ! $mapping['isOwningSide']) { throw MappingException::illegalToManyAssociationOnMappedSuperclass($parentClass->name, $field); } - - if (! isset($mapping['inherited'])) { - $mapping['sourceEntity'] = $subClass->name; - } } //$subclassMapping = $mapping; @@ -396,6 +392,16 @@ private function addInheritedRelations(ClassMetadata $subClass, ClassMetadata $p $mapping['declared'] = $parentClass->name; } + // When the class inheriting the relation ($subClass) is the first entity class since the + // relation has been defined in a mapped superclass (or in a chain + // of mapped superclasses) above, then declare this current entity class as the source of + // the relationship. + // According to the definitions given in https://github.com/doctrine/orm/pull/10396/, + // this is the case <=> ! isset($mapping['inherited']). + if (! isset($mapping['inherited'])) { + $mapping['sourceEntity'] = $subClass->name; + } + $subClass->addInheritedAssociationMapping($mapping); } }