-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Keep the
declared
mapping information when using attribute overrides (
#11135) When using `AttributeOverride` to override mapping information inherited from a parent class (a mapped superclass), make sure to keep information about where the field was originally declared. This is important for `private` fields: Without the correct `declared` information, it will lead to errors when cached mapping information is loaded, reflection wakes up and looks for the private field in the wrong class.
- Loading branch information
Showing
3 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
tests/Doctrine/Tests/ORM/Functional/Ticket/GH11135Test.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Functional\Ticket; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
use Doctrine\Tests\OrmFunctionalTestCase; | ||
|
||
class GH11135Test extends OrmFunctionalTestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->setUpEntitySchema([ | ||
GH11135MappedSuperclass::class, | ||
GH11135EntityWithOverride::class, | ||
GH11135EntityWithoutOverride::class, | ||
]); | ||
} | ||
|
||
public function testOverrideInheritsDeclaringClass(): void | ||
{ | ||
$cm1 = $this->_em->getClassMetadata(GH11135EntityWithOverride::class); | ||
$cm2 = $this->_em->getClassMetadata(GH11135EntityWithoutOverride::class); | ||
|
||
self::assertSame($cm1->getFieldMapping('id')['declared'], $cm2->getFieldMapping('id')['declared']); | ||
self::assertSame($cm1->getAssociationMapping('ref')['declared'], $cm2->getAssociationMapping('ref')['declared']); | ||
} | ||
} | ||
|
||
/** | ||
* @ORM\MappedSuperclass | ||
*/ | ||
class GH11135MappedSuperclass | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\Column(type="integer") | ||
* @ORM\GeneratedValue | ||
* | ||
* @var int | ||
*/ | ||
private $id; | ||
|
||
/** | ||
* @ORM\ManyToOne(targetEntity="GH11135EntityWithoutOverride") | ||
* | ||
* @var GH11135EntityWithoutOverride | ||
*/ | ||
private $ref; | ||
} | ||
|
||
/** | ||
* @ORM\Entity() | ||
* @ORM\AttributeOverrides({ | ||
* @ORM\AttributeOverride(name="id", column=@ORM\Column(name="id_overridden")) | ||
* }) | ||
* @ORM\AssociationOverrides({ | ||
* @ORM\AssociationOverride(name="ref", joinColumns=@ORM\JoinColumn(name="ref_overridden", referencedColumnName="id")) | ||
* }) | ||
*/ | ||
class GH11135EntityWithOverride extends GH11135MappedSuperclass | ||
{ | ||
} | ||
|
||
/** | ||
* @ORM\Entity() | ||
*/ | ||
class GH11135EntityWithoutOverride extends GH11135MappedSuperclass | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters