I am still trying to understand polymorphic associations in Doctrine2.
As I understand it, basic polymorphic associations work by using inheritance. If, for example, I had tables/classes OWNER
, CAT
and DOG
, then the way to enable $owner->pet
to point at either the CAT
or the DOG
table, would be to have them each extend a fourth class, PET
, which is known as a mapped superclass. Then $owner->pet
could return either a CAT
or a DOG
depending on what had been assigned, and Doctrine2 would be able to distinguish them.
That's simple enough. But what if I want to have two polymorphic associations which can point at the same object? For example, lets say that I have a table of ADMIRALS
, each of which could command a FLEET
or a PLANET
. Let's also say that I have a table of SECTORS
, each of which could contain a PLANET
or a MOON
.
Let's assume that I want $admiral->command
to reference both PLANETS
and FLEETS
, and that I want $sector->contents
to reference both PLANETS
and MOONS
. PLANET
can't extend both command
and contents
as mapped superclasses. Is there a different way to make this work?
you can try ResolveTargetEntityListener see
you can point admiral's command property to an Interface, which is implemented by both PLANETS and FLEETS
the same is with sector's contents