diff --git a/src/Mapping/Driver/ReflectionBasedDriver.php b/src/Mapping/Driver/ReflectionBasedDriver.php index a2900d13e01..9becf228a31 100644 --- a/src/Mapping/Driver/ReflectionBasedDriver.php +++ b/src/Mapping/Driver/ReflectionBasedDriver.php @@ -32,8 +32,13 @@ private function isRepeatedPropertyDeclaration(ReflectionProperty $property, Cla || $metadata->isInheritedEmbeddedClass($property->name); } + /** @var class-string $declaringClass */ $declaringClass = $property->class; + if ($this->isTransient($declaringClass)) { + return isset($metadata->fieldMappings[$property->name]); + } + if ( isset($metadata->fieldMappings[$property->name]['declared']) && $metadata->fieldMappings[$property->name]['declared'] === $declaringClass diff --git a/tests/Tests/ORM/Functional/Ticket/GH10450Test.php b/tests/Tests/ORM/Functional/Ticket/GH10450Test.php index c522049f820..afe75d3bcdf 100644 --- a/tests/Tests/ORM/Functional/Ticket/GH10450Test.php +++ b/tests/Tests/ORM/Functional/Ticket/GH10450Test.php @@ -32,6 +32,15 @@ public function classesThatOverrideFieldNames(): Generator yield 'Entity class that redeclares a protected field inherited from a base entity' => [GH10450EntityChildProtected::class]; yield 'Entity class that redeclares a protected field inherited from a mapped superclass' => [GH10450MappedSuperclassChildProtected::class]; } + + public function testFieldsOfTransientClassesAreNotConsideredDuplicate(): void + { + $em = $this->getTestEntityManager(); + + $metadata = $em->getClassMetadata(GH10450Cat::class); + + self::assertArrayHasKey('id', $metadata->fieldMappings); + } } /** @@ -179,3 +188,38 @@ class GH10450MappedSuperclassChildProtected extends GH10450BaseMappedSuperclassP */ protected $field; } + +abstract class GH10450AbstractEntity +{ + /** + * @ORM\Column(type="integer") + * @ORM\Id + * @ORM\GeneratedValue + * + * @var int + */ + protected $id; +} + +/** + * @ORM\Entity + * @ORM\InheritanceType("SINGLE_TABLE") + * @ORM\DiscriminatorMap({ "cat": "GH10450Cat" }) + * @ORM\DiscriminatorColumn(name="type") + */ +abstract class GH10450Animal extends GH10450AbstractEntity +{ + /** + * @ORM\Column(type="text", name="base") + * + * @var string + */ + private $field; +} + +/** + * @ORM\Entity + */ +class GH10450Cat extends GH10450Animal +{ +}