[英]How to complete an entity with relations which cannot be mapped by doctrine
I have an entity person
, which is linked to an person_groups
table. 我有一个实体
person
,该实体链接到person_groups
表。 As this link is not done through person.id
primary key, but through an index person.matricule
, I cannot map this attribute with a many to one relation However, I'd really like to have a groups
property in my entity. 由于此链接不是通过
person.id
主键完成的,而是通过索引person.matricule
,因此我无法将此属性与多个关系进行映射。但是,我真的很想在我的实体中拥有一个groups
属性。 How can this be achieved ? 如何实现呢?
I was thinking of using the doctrine event lifecycle, to dynamically update my entity at load time. 我当时正在考虑使用主义事件生命周期来在加载时动态更新我的实体。 Is it a good idea ?
这是个好主意吗 ? Are there other solutions ?
还有其他解决方案吗?
What is the reason you can't map it by doctrine? 您无法按学说来映射它的原因是什么?
/**
* @ORM\OneToMany(
* targetEntity="YourNamespace\YourEntityGroups",
* mappedBy="person"
* )
*/
protected $groups;
and 和
/**
* @ORM\ManyToOne(
* targetEntity="YourNamespace\YourEntityPerson",
* inversedBy="groups"
* )
* @ORM\JoinColumn(name="person_matricule", referencedColumnName="matricule")
*/
protected $person;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.