Skip to content

Commit

Permalink
Merge pull request #11769 from HypeMC/fix-reportfieldswheredeclared
Browse files Browse the repository at this point in the history
Fix fields of transient classes being considered duplicate with `reportFieldsWhereDeclared`
  • Loading branch information
greg0ire authored Jan 20, 2025
2 parents c12fd2c + 4feaa47 commit 5ad5b11
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Mapping/Driver/ReflectionBasedDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 44 additions & 0 deletions tests/Tests/ORM/Functional/Ticket/GH10450Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

/**
Expand Down Expand Up @@ -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
{
}

0 comments on commit 5ad5b11

Please sign in to comment.