简体   繁体   中英

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. 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. 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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM