How can I change the mapping info of a Doctrine entity dynamically?

Go To StackoverFlow.com

0

I have an annotations mapping on an entity that will have an ManyToOne association of type "Person" but depending on the circumstances I want to change the type of that relation to a more specific one, for example "Student".

How can I change the relationship mapping information dynamically?

PD: Actually I want to do this as a workaround of other problem ( Not finding field in polymorphic association with Doctrine2 )

2012-04-04 03:49
by dimirc


1

I did it like this:

    $cmf = $this->em->getMetadataFactory();
    $class = $cmf->getMetadataFor("Article");
    $class->associationMappings["person"]["targetEntity"]="User";
2012-04-04 05:15
by dimirc
Be aware that your change will not be persisted. Also, if you change it during Doctrine execution, you might get inconsistent entities. I would not recommend to do so. Please read about targetEntityListene - Alexandre Salomé 2013-11-08 10:52
Ads