1
votes

I have an abstract entity model class that have inheritance type "joined".

If I want to extend that entity in another bundle, I need to add the "children class" into the discriminator map .. But if its in another bundle, that means I will need to modify the parent bundle entity every time that I want to extend that model into another bundle, and I think that this does make a little sense.

So if I want to not need to modify the abstract class discriminator map every time that I extend it with a new entity in a new bundle, is it possible to say Doctrine or SF2 that the "discr" field must equal the children entity class name + its namespace, so this way it will be way more dynamic so I don't have to edit my parent bundle every time that I want to extend it.

Mapped superclass is not a good option because I need one-to-many relationship.

So my question is clearly : How I can avoid to manually set "DiscriminatorMap" so that field be automatically set to the children class name + namespace ? (discr = inherited class name + namespace)

This is example that would be cool :

/**
* Operable
*
* @ORM\Table()
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="discr", type="string")
* @ORM\DiscriminatorMap(**AUTOMATIC**)
* @ORM\Entity(repositoryClass="FOO\PaymentBundle\Entity\OperableRepository")
* @ORM\HasLifecycleCallbacks
*/
abstract class Operable     {
    /* some good stuff */
}

Thank you very much to all of you and have a great day !

1

1 Answers

0
votes

After taking time to carefully read the doc, the solution is way very simple :

Simply to remove "@ORM\DiscriminatorColumn" annotation from there !

The names of the classes in the discriminator map do not need to be fully qualified if the classes are contained in the same namespace as the entity class on which the discriminator map is applied.

If no discriminator map is provided, then the map is generated automatically. The automatically generated discriminator map contains the lowercase short name of each class as key.

(source : http://doctrine-orm.readthedocs.org/en/latest/reference/inheritance-mapping.html)