2013-04-26 134 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