dimirc
dimirc

Reputation: 6605

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

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 )

Upvotes: 0

Views: 611

Answers (1)

dimirc
dimirc

Reputation: 6605

I did it like this:

    $cmf = $this->em->getMetadataFactory();
    $class = $cmf->getMetadataFor("Article");
    $class->associationMappings["person"]["targetEntity"]="User";

Upvotes: 1

Related Questions