Symfony2 + doctrine2表关系设计

时间:2013-04-26 05:38:30

标签: doctrine-orm symfony-2.1

我正在使用带有doctrine2的Symfony2,我需要设计与yml文件的表关系。 这些表是:用户,帐户和角色,其中用户可以是许多帐户的成员,并且具有不同的角色。

如果没有学说,我会用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

1 个答案:

答案 0 :(得分:0)

在这种情况下,您可以选择的唯一方法是创建另一个名为UserAccountRole的实体,并使用OneToMany连接到该实体。

User -> (OneToMany) -> UserAccountRole -> (ManyToOne) -> User
Account -> (OneToMany) -> UserAccountRole -> (ManyToOne) -> Account
Role -> (OneToMany) -> UserAccountRole -> (ManyToOne) -> Role
相关问题