Description
We have an entity hierarchy similar to:
/**
* @ORM\Entity
* @ORM\Table(name="AbstractInvoiceItem")
*
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="type")
* @ORM\DiscriminatorMap({
* "SetupFee" = SetupFee::class
* })
*/
abstract class AbstractInvoiceItem
{
}
/**
* @MappedSuperclass
*/
abstract class AbstractProductInvoiceItem extends AbstractInvoiceItem
{
/**
* @ORM\ManyToOne(targetEntity=AbstractProduct::class)
*/
protected ?AbstractProduct $product;
}
/**
* @ORM\Entity
* @ORM\Table(name=SetupFee")
*/
class SetupFee extends AbstractProductInvoiceItem
{
}
This was working fine with Doctrine 2.8.
Since we upgraded to Doctrine 2.9 however, bin/console doctrine:schema:validate
started failing with:
[FAIL] The entity-class App(...)\AbstractProductInvoiceItem mapping is invalid:
- Entity class 'App(...)\AbstractProductInvoiceItem' is part of inheritance hierarchy, but is not mapped in the root entity 'App(...)\AbstractInvoiceItem' discriminator map. All subclasses must be listed in the discriminator map.
I tried adding a "fake" entry to the discriminator map for the abstract class:
/*
* @ORM\DiscriminatorMap({
* "AbstractProductInvoiceItem" = AbstractProductInvoiceItem::class,
* "SetupFee" = SetupFee::class
* })
*/
But now Doctrine attempts to JOIN
a non-existing table when loading an entity in the hierarchy:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'abstract_product_invoice_item' doesn't exist
How can I fix this?
A solution would be to make the intermediate abstract class an entity, but this would mean that $product
would be moved from leaf entities to a new AbstractProductInvoiceItem
table, which adds an extra JOIN
to every query, and would mean a rather scary migration to do.
Is there a better solution? Or are MappedSuperclasses not allowed in the middle of an entity hierarchy anymore?