NOTE : if what I want is not possible, a "not possible" answer will be accepted
In the Doctrine 2 documentation about inheritance mapping, it says there are 2 ways :
- Single table inheritance (STI)
- Class table inheritance (CTI)
For both, there is the warning :
If you use a STI/CTI entity as a many-to-one or one-to-one entity you should never use one of the classes at the upper levels of the inheritance hierachy as “targetEntity”, only those that have no subclasses. Otherwise Doctrine CANNOT create proxy instances of this entity and will ALWAYS load the entity eagerly.
So, how can I proceed to use inheritance with an association to the base (abstract) class ? (and keep the performance of course)
Example
A user has many Pet
(abstract class extended by Dog
or Cat
).
What I want to do :
class User {
/**
* @var array(Pet) (array of Dog or Cat)
*/
private $pets;
}
Because of the warning in Doctrine documentation, I should do that :
class User {
/**
* @var array(Dog)
*/
private $dogs;
/**
* @var array(Cat)
*/
private $cats;
}
This is annoying, because I loose the benefits of inheritance !
Note : I didn't add the Doctrine annotations for the mapping to DB, but you can understand what I mean