diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index ec08ac839e6..163be61248a 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -1698,7 +1698,7 @@ private function getSelectConditionStatementColumnSQL($field, $assoc = null) if (isset($this->class->fieldMappings[$field])) { // Fix for bug GH-8229 (id column from parent class renamed in child class): // Use the correct metadata and name for the id column - if (isset($this->class->fieldMappings[$field]['inherited'])) { + if (isset($this->class->fieldMappings[$field]['inherited']) && $this->class->inheritanceType !== ClassMetadata::INHERITANCE_TYPE_NONE) { $className = $this->class->fieldMappings[$field]['inherited']; $class = $this->em->getClassMetadata($className); } else { diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH8229Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH8229Test.php index e32ff11c59e..c03e7edfc89 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH8229Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH8229Test.php @@ -23,6 +23,8 @@ protected function setUp() : void [ GH8229Resource::class, GH8229User::class, + GH8229EntityWithoutDiscriminator::class, + EntityExtendingGH8229EntityWithoutDiscriminator::class, ] ); } @@ -183,6 +185,19 @@ public function testCorrectColumnNamesInPessimisticWriteLock() self::assertEquals($identifier, $entity->id); } + + /** this test check alias generation not altered by inheritance in ResolvedTargetEntities mapped classes + */ + public function testBasicEntityPersisterAliasGenerationWithSimpleInheritance() + { + $this->expectNotToPerformAssertions(); + + $entity = new EntityExtendingGH8229EntityWithoutDiscriminator(); + $this->_em->persist($entity); + $this->_em->flush(); + + $this->_em->getRepository(EntityExtendingGH8229EntityWithoutDiscriminator::class)->findOneBy(['id' => $entity->getId()]); + } } @@ -244,3 +259,29 @@ public function __construct($username) $this->username = $username; } } + +/** + * @Entity + * @Table(name="gh8229_replacedentity") + */ +class GH8229EntityWithoutDiscriminator +{ + /** + * @Id + * @GeneratedValue + * @Column(type="integer") + */ + public $id; + + public function getId() + { + return $this->id; + } +} + +/** + * @Entity + */ +final class EntityExtendingGH8229EntityWithoutDiscriminator extends GH8229EntityWithoutDiscriminator +{ +}