如何在Doctrine 2中使用多个targetEntity?

时间:2015-02-08 05:43:06

标签: php symfony orm doctrine-orm doctrine

我有两张桌子:

Event.orm.yml

manyToOne:
    last_author:
        targetEntity: User
        inversedBy: last_author_contact
        joinColumn:
            name: last_author_id
            referencedColumnName: id

User.orm.yml

oneToMany:
    last_author_contact:
        targetEntity: Event
        mappedBy: last_author

现在我想添加与“User”实体连接的新“Project”实体。 所以我必须写 User.orm.yml

oneToMany:
        last_author_contact:
            targetEntity: Event
            mappedBy: last_author
        last_author_project_contact:
            targetEntity: Project
            mappedBy: last_author_project

创建 Project.orm.yml

manyToOne:
        last_author_project:
            targetEntity: User
            inversedBy: last_author_project_contact
            joinColumn:
                name: last_author_id
                referencedColumnName: id

如何使用多个targetEntity并且无法在用户实体(setter和getters)中编写类似的代码?

像这样:

oneToMany:
    last_author_contact:
        targetEntity: Event
        targetEntity: Project
        mappedBy: last_author

0 个答案:

没有答案