Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fields of transient classes being considered duplicate with reportFieldsWhereDeclared #11769

Open
wants to merge 1 commit into
base: 2.20.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
{
}