Skip to content

Commit

Permalink
Merge pull request doctrine#10517 from greg0ire/3.0.x
Browse files Browse the repository at this point in the history
Merge 2.15.x up into 3.0.x
  • Loading branch information
greg0ire committed Feb 12, 2023
2 parents 0f77181 + 7a7464e commit 21c3f4d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
6 changes: 6 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,12 @@ Use `toIterable()` instead.

# Upgrade to 2.15

## Deprecated overriding fields or associations not declared in mapped superclasses

As stated in the documentation, fields and associations may only be overridden when being inherited
from mapped superclasses. Overriding them for parent entity classes now triggers a deprecation notice
and will be an error in 3.0.

## Deprecated undeclared entity inheritance

As soon as an entity class inherits from another entity class, inheritance has to
Expand Down
14 changes: 10 additions & 4 deletions lib/Doctrine/ORM/Mapping/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -2230,10 +2230,16 @@ public function setAttributeOverride(string $fieldName, array $overrideMapping):

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

//if (isset($mapping['inherited'])) {
// 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($mapping['id'])) {
$overrideMapping['id'] = $mapping['id'];
Expand Down
3 changes: 1 addition & 2 deletions lib/Doctrine/ORM/Mapping/MappingException.php
Original file line number Diff line number Diff line change
Expand Up @@ -551,8 +551,7 @@ public static function illegalOverrideOfInheritedProperty(string $className, str
{
return new self(
sprintf(
'Override for %s::%s is only allowed for attributes/associations ' .
'declared on a mapped superclass or a trait.',
'Overrides are only allowed for fields or associations declared in mapped superclasses or traits, which is not the case for %s::%s.',
$className,
$propertyName,
),
Expand Down
11 changes: 11 additions & 0 deletions tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Doctrine\ORM\Mapping\Table;
use Doctrine\ORM\Mapping\UniqueConstraint;
use Doctrine\Persistence\Mapping\RuntimeReflectionService;
use Doctrine\Tests\Models\Company\CompanyFixContract;
use Doctrine\Tests\Models\DDC869\DDC869ChequePayment;
use Doctrine\Tests\Models\DDC869\DDC869CreditCardPayment;
use Doctrine\Tests\Models\DDC869\DDC869Payment;
Expand Down Expand Up @@ -253,6 +254,16 @@ public function invalidHierarchyDeclarationClasses(): Generator
yield 'complex example (Entity Root -> Mapped Superclass -> transient class -> Entity)'
=> [InvalidComplexRoot::class, InvalidComplexEntity::class];
}

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

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

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

class TransientBaseClass
Expand Down

0 comments on commit 21c3f4d

Please sign in to comment.