[英]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".我在一个实体上有一个注释映射,该实体将具有“人”类型的 ManyToOne 关联,但根据情况我想将该关系的类型更改为更具体的类型,例如“学生”。
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 ) PD:实际上我想这样做是为了解决其他问题( Not finding field in polymorphic association with Doctrine2 )
I did it like this:我是这样做的:
$cmf = $this->em->getMetadataFactory();
$class = $cmf->getMetadataFor("Article");
$class->associationMappings["person"]["targetEntity"]="User";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.