2013-04-26 64 views
0

我使用Symfony2與doctrine2,我需要設計與yml文件的表關係。 這些表格是:用戶,帳戶和角色,其中用戶可以成爲許多帳戶的成員並具有不同的角色。Symfony2 + doctrine2表關係設計

沒有教條我會創建表和一個與user_id,account_id和role_id連接表。

隨着教條我現在有這個,我正在尋找一個提示如何添加一個更多的關係到表角色。

User: 
    type: entity 
    manyToMany: 
     accounts: 
      targetEntity: Accounts 
      joinTable: 
      name: UserAccount 
      joinColumns: 
       user_id: 
       referencedColumnName: id 
      inverseJoinColumns: 
       account_id: 
       referencedColumnName: id 
+0

那麼角色也依賴於帳戶? – 2013-04-26 07:10:48

+0

[Doctrine2:處理多對多參考表中額外列的最佳方法]的可能重複(http://stackoverflow.com/questions/3542243/doctrine2-best-way-to-handle-many-to-許多與 - 特列 - 在引用表) – Florian 2013-04-26 14:13:21

回答

0

在這種情況下,你可以去的唯一方法是創建一個名爲另一個實體,讓說UserAccountRoleOneToMany連接到它。

User -> (OneToMany) -> UserAccountRole -> (ManyToOne) -> User 
Account -> (OneToMany) -> UserAccountRole -> (ManyToOne) -> Account 
Role -> (OneToMany) -> UserAccountRole -> (ManyToOne) -> Role