【问题标题】:Symfony2 + doctrine2 table relation designSymfony2 + 学说2 表关系设计
【发布时间】:2013-04-20 05:09:02
【问题描述】:

我将 Symfony2 与学说 2 一起使用,我需要设计与 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

【问题讨论】:

标签: doctrine-orm symfony-2.1


【解决方案1】:

在这种情况下,您唯一的办法就是创建另一个名为 UserAccountRole 的实体,然后使用 OneToMany 连接到它。

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

【讨论】:

    猜你喜欢
    • 2017-01-22
    • 1970-01-01
    • 1970-01-01
    • 2013-12-01
    • 2014-09-29
    • 1970-01-01
    • 2012-04-14
    • 2012-03-11
    • 1970-01-01
    相关资源
    最近更新 更多