Skip to content

Commit

Permalink
Merge pull request #10519 from mpdude/deprecate-override-association
Browse files Browse the repository at this point in the history
Deprecate overriding associations not inherited from a mapped superclass
  • Loading branch information
greg0ire committed Apr 7, 2023
2 parents b984b56 + 8efdcb0 commit a78e5bc
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 @@ -2465,12 +2465,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 a78e5bc

Please sign in to comment.