2017-08-04 49 views
1

我有一個實體person,它鏈接到一個person_groups表。 由於此鏈接不是通過person.id主鍵完成的,而是通過索引person.matricule完成的,因此我無法將此屬性與多對一關係進行映射。 但是,我真的很想在我的實體中擁有groups屬性。這怎麼能實現?如何完成一個實體的關係,不能由原則映射

我正在考慮使用doctrine事件生命週期,以便在加載時動態更新我的實體。這是個好主意嗎 ?還有其他解決方案嗎?

回答

0

你不能按照教義映射它的原因是什麼?

/** 
* @ORM\OneToMany(
*  targetEntity="YourNamespace\YourEntityGroups", 
*  mappedBy="person" 
*) 
*/ 
protected $groups; 

/** 
* @ORM\ManyToOne(
*  targetEntity="YourNamespace\YourEntityPerson", 
*  inversedBy="groups" 
*) 
* @ORM\JoinColumn(name="person_matricule", referencedColumnName="matricule") 
*/ 
protected $person; 
+0

因爲教義只能加入上主鍵:http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/limitations-and -known-issues.html – toubab

相關問題