Ajouve
Ajouve

Reputation: 10089

empty inherited entity Symfony2

I have for exemple this schema

abstract class Class1

    attr1
    attr2

class Class2 extends Class1

    /**
    * @ORM\OneToMany("Class3")
    */
    attr3Array

class Class3

    /**
    * @ORM\ManyToOne(targetEntity="Class2")
    */
    attr3

This is just a pseudo code to present my problem. When I try to generate my database I have this error

[Doctrine\ORM\Mapping\MappingException]
Entity 'Class2' has to be part of the discriminator map of 'Class1' to be properly mapped   
  in the inheritance hierarchy. Alternatively you can make 'Class2' an abstract class to avoid this exception from occurring.  

But I want to create instances of Class2, I don't want an abstract Class2 Is there an other way to model my entities ?

Upvotes: 3

Views: 895

Answers (1)

Adam Elsodaney
Adam Elsodaney

Reputation: 7808

Try defining the parent class as a mapped superclass. If there is an @ORM\Entity annotation, you'll need to remove that.

/**
 * @ORM\MappedSuperclass
 */
abstract class Class1
{
}

You may also have to make this class non-abstract if Doctrine doesn't like MappedSuperclasses to be abstract.

More information on inheritance mapping can be found in the docs. Also you may find a more suitable solution in there for what you need.

Upvotes: 2

Related Questions