【问题标题】:Doctrine2 - How set oneToOne entity not by idDoctrine2 - 如何不按 id 设置 oneToOne 实体
【发布时间】:2013-05-29 20:02:31
【问题描述】:

这是映射信息的一部分:

id:
    type: integer
    id: true
    generator:
        strategy: AUTO
ms_id:
    type: string
    unique: true
oneToOne:
    parent:
        targetEntity: Category
        nullable: true

如何使用 ms_id 而不是 id 建立连接

【问题讨论】:

    标签: php symfony orm doctrine


    【解决方案1】:

    您可以使用referencedColumnName指定连接列参数, 见association mapping document

    id:
        type: integer
        id: true
        generator:
            strategy: AUTO
    ms_id:
        type: string
        unique: true
    oneToOne:
        parent:
            targetEntity: Category
            joinColumn:
              name: category_id
              referencedColumnName: ms_id
            nullable: true
    

    【讨论】:

    • 谢谢...我试过了,但首先需要 drop 和 create db。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-17
    • 1970-01-01
    • 1970-01-01
    • 2011-11-13
    相关资源
    最近更新 更多