Skip to content

Commit 200b4c6

Browse files
committed
Turn deprecation from doctrine#10470 into an exception in 3.0.x
1 parent 21c3f4d commit 200b4c6

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

UPGRADE.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Upgrade to 3.0
22

3+
## BC BREAK: Overriding fields or associations declared in other than mapped superclasses
4+
5+
As stated in the documentation, fields and associations may only be overridden when being inherited
6+
from mapped superclasses. Overriding them for parent entity classes now throws a `MappingException`.
7+
38
## BC BREAK: Undeclared entity inheritance now throws a `MappingException`
49

510
As soon as an entity class inherits from another entity class, inheritance has to

lib/Doctrine/ORM/Mapping/ClassMetadata.php

+1-8
Original file line numberDiff line numberDiff line change
@@ -2231,14 +2231,7 @@ public function setAttributeOverride(string $fieldName, array $overrideMapping):
22312231
$mapping = $this->fieldMappings[$fieldName];
22322232

22332233
if (isset($mapping['inherited'])) {
2234-
Deprecation::trigger(
2235-
'doctrine/orm',
2236-
'https://github.com/doctrine/orm/pull/10470',
2237-
'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.',
2238-
$this->name,
2239-
$fieldName,
2240-
$mapping['inherited'],
2241-
);
2234+
throw MappingException::illegalOverrideOfInheritedProperty($this->name, $fieldName, $mapping['inherited']);
22422235
}
22432236

22442237
if (isset($mapping['id'])) {

lib/Doctrine/ORM/Mapping/MappingException.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -547,13 +547,14 @@ public static function infiniteEmbeddableNesting(string $className, string $prop
547547
);
548548
}
549549

550-
public static function illegalOverrideOfInheritedProperty(string $className, string $propertyName): self
550+
public static function illegalOverrideOfInheritedProperty(string $className, string $propertyName, string $inheritFromClass): self
551551
{
552552
return new self(
553553
sprintf(
554-
'Overrides are only allowed for fields or associations declared in mapped superclasses or traits, which is not the case for %s::%s.',
554+
'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.',
555555
$className,
556556
$propertyName,
557+
$inheritFromClass
557558
),
558559
);
559560
}

tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ public function testInvalidOverrideFieldInheritedFromEntity(): void
260260
{
261261
$cm = $this->cmf->getMetadataFor(CompanyFixContract::class);
262262

263-
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/pull/10470');
263+
$this->expectException(MappingException::class);
264+
$this->expectExceptionMessageMatches('/Overrides are only allowed for fields or associations declared in mapped superclasses or traits./');
264265

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

0 commit comments

Comments
 (0)