orm
orm copied to clipboard
Deprecation false positive(?): Embeddable reported to require inheritance mapping type
Bug Report
| Q | A |
|---|---|
| Version | 2.20.2 |
Summary
We are currently migrating a project to Doctrine 3 and are encountering the following deprecation.
Entity class 'App\Domain\Value\BoundedTimeframe' is a subclass of the root entity class 'App\Domain\Value\Timeframe', but no inheritance mapping type was declared. This is a misconfiguration and will be an error in Doctrine ORM 3.0. (ClassMetadataFactory.php:165 called by ClassMetadataFactory.php:18, https://github.com/doctrine/orm/pull/10431, package doctrine/orm)
Current behavior
The deprecation about entity inheritance is raised on embeddables.
Expected behavior
There has been no issue within Doctrine 2 using this pattern. As you cannot define inheritance types on embeddables, the deprecation should not be raised for them. In addition, the behavior should work in Doctrine 3, as well. Will it?
How to reproduce
<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<embeddable name="App\Domain\Value\Timeframe">
<field name="from" type="datetime_immutable" column="from" nullable="true" />
<field name="to" type="datetime_immutable" column="to" nullable="true" />
</embeddable>
</doctrine-mapping>
<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<embeddable name="App\Domain\Value\BoundedTimeframe" />
</doctrine-mapping>
// Simplified
class Timeframe
{
public function __construct(
protected readonly \DateTimeImmutable|null $from,
protected readonly \DateTimeImmutable|null $to,
) {
}
}
class BoundedTimeframe extends Timeframe
{
public function __construct(\DateTimeImmutable $from, \DateTimeImmutable $to)
{
parent::__construct($from, $to);
}
}
Possible next steps:
- convert the provided reproducer to a test
- address the issue by adding a condition on
$class->isEmbeddedClassto the code added in https://github.com/doctrine/orm/pull/10431
My current workaround is to simply add inheritance-type="JOINED". While this silences the deprecation, it does not seem to have any effect at runtime. This also works with Doctrine v3.3.2.
<embeddable name="App\Domain\Value\Timeframe" inheritance-type="JOINED">