I have read Doctrine 2 Inheritance Mapping with Association but say if you needed Animal
to be an entity in its own right, say for creating option lists.
In this case the Discriminator Column for a Pet
is in the species column in the animal table
.
So the classes would be something like this.
class Animal
{
$id;
$species;
}
/**
* @Table(name="animal")
* @InheritanceType("JOINED")
* @DiscriminatorColumn(name="species", type="string")
* @DiscriminatorMap({"dog" = "Dog", "cat" = "Cat"})
*/
abstract class Pet
{
$id
$species;
}
class Dog extends Pet { }
class Cat extends Pet { }
class Owner
{
/**
* @OneToMany(targetEntity="Pet")
*/
$pets
}
I see a couple of problems.
the
animal
table doesn't have a foreign key toowner
. So the the$pets
association isn't going to work.Animal
andPet
are more or less that same thing. If some one changes something inAnimal
those changes wouldn't be reflected in anyPet
subclasses.
A possible solution to the first problem would be to have an extra table called pet
, but there is still an issue with the association, because the discriminator column is still in the animal
table and duplicating the column in pet
would break normalisation.