Skip to content

Commit

Permalink
Deprecate overriding associations not inherited from a mapped superclass
Browse files Browse the repository at this point in the history
  • Loading branch information
mpdude committed Feb 13, 2023
1 parent 3810a0b commit 8efdcb0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -2526,12 +2526,16 @@ public function setAssociationOverride($fieldName, array $overrideMapping)

$mapping = $this->associationMappings[$fieldName];

//if (isset($mapping['inherited']) && (count($overrideMapping) !== 1 || ! isset($overrideMapping['fetch']))) {
// TODO: Deprecate overriding the fetch mode via association override for 3.0,
// users should do this with a listener and a custom attribute/annotation
// TODO: Enable this exception in 2.8
//throw MappingException::illegalOverrideOfInheritedProperty($this->name, $fieldName);
//}
if (isset($mapping['inherited'])) {
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/pull/10470',
'Overrides are only allowed for fields or associations declared in mapped superclasses or traits. This is not the case for %s::%s, which was inherited from %s. This is a misconfiguration and will be an error in Doctrine ORM 3.0.',
$this->name,
$fieldName,
$mapping['inherited']
);
}

if (isset($overrideMapping['joinColumns'])) {
$mapping['joinColumns'] = $overrideMapping['joinColumns'];
Expand Down
10 changes: 10 additions & 0 deletions tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,16 @@ public function testInvalidOverrideFieldInheritedFromEntity(): void

$cm->setAttributeOverride('completed', ['name' => 'other_column_name']);
}

/** @group DDC-964 */
public function testInvalidOverrideAssociationInheritedFromEntity(): void
{
$cm = $this->cmf->getMetadataFor(CompanyFixContract::class);

$this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/pull/10470');

$cm->setAssociationOverride('salesPerson', ['inversedBy' => 'other_inversed_by_name']);
}
}

class TransientBaseClass
Expand Down

0 comments on commit 8efdcb0

Please sign in to comment.