This is the configuration I want to have:
An Entity "Account" with a JOINED inheritance to two other Entities: "Author" and "AccountBackend".
Then I would want the "AccountBackend" to have a SINGLE_TABLE inheritance with other two Entities: "Administrator" and "FeaturedAuthor". This is the way I have them defined:
Account.php
/**
* @Entity (repositoryClass="Repositories\Account")
* @Table(name="accounts")
* @InheritanceType("JOINED")
* @DiscriminatorColumn(name="discr", type="integer")
* @DiscriminatorMap({"1"="Author","2"="AccountBackend"})
* @HasLifecycleCallbacks
*/
class Account
{
Curator.php
/**
* @Entity
* @Table(name="accounts_author")
*/
class Author extends Account
{
AccountBackend.php
/**
* @Entity (repositoryClass="Repositories\AccountBackend")
* @Table(name="accounts_backend")
* @InheritanceType("SINGLE_TABLE")
* @DiscriminatorColumn(name="discr", type="integer")
* @DiscriminatorMap({"1"="FeaturedAuthor","2"="Administrator"})
* @HasLifecycleCallbacks
*/
class AccountBackend extends Account
{
FeaturedAuthor.php
/**
* @Entity
*/
class FeaturedAuthor extends AccountBackend
{
Administrator.php
/**
* @Entity
*/
class Administrator extends AccountBackend
{
When I have them defined, when I try to do an update through the CLI it says
"Entity 'Entities\AccountBackend' has to be part of the discriminator map of 'Entities\Account' to be properly mapped in the inheritance hierachy. Alternatively you can make 'Entities\AccountBackend' an abstract class to avoid this exception from occuring."
I don't see anything wrong with the way I defined them, this is the first time that I try to have inheritance on an already inherited Entity. Any idea of whats wrong? Thanks!
You need a case for your "AccountBackend" class in your @DiscriminatorMap
e.g
@DiscriminatorMap({"1"="FeaturedAuthor","2"="Administrator", "3"="AccountBackend"})
As explain in the Documentation
All entity classes that is part of the mapped entity hierarchy (including the topmost class) should be specified in the @DiscriminatorMap. In the case above Person class included.
In case you came here & had problem with SINGLE_TABLE inheritance - possible that the problem occurs because your discriminator class is not abstract.
My case example (solution)
/**
* @ORM\InheritanceType("SINGLE_TABLE")
* @ORM\DiscriminatorColumn(name="entity", type="string")
* @ORM\DiscriminatorMap({"product" = "ProductReview", "seller" = "SellerReview"})
* @ORM\Table(name="reviews")
*/
abstract class Review {}
class ProductReview extends Review {}
class SellerReview extends Review {}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With