【问题标题】:Unique column in many to many association doctrine 2多对多关联学说2中的唯一列
【发布时间】:2015-09-03 12:27:01
【问题描述】:

我在 yaml 文档中使用了一对多、单向和联接表关联,但在数据库中没有创建唯一约束。

我正在使用 postgres。我做错了什么?

这是我的实体,它有两个“一对多、单向和连接表”关联“问题”和“答案”

TestCasesPersistence\Entities\GroupQA:
    type: entity
    table: group_qa
    id:
        id:
            type: integer
            nullable: false
            length: null
            fixed: false
            id: true
            column: id
            generator:
                strategy: IDENTITY
    fields:
        name:
            type: string
            nullable: true
            length: null
            fixed: false
            column: name
        timeCreated:
            type: datetime
            nullable: true
            column: time_created
    manyToMany:
        questions:
            targetEntity: Question
            joinTable:
                name: group_qa_questions
            joinColumns:
                group_qa_id:
                    referencedColumnName: id
            inverseJoinColumns:
                question_id:
                    unique: true
                    referencedColumnName: id
        answers:
            targetEntity: Answer
            joinTable:
                name: group_qa_answers
            joinColumns:
                group_qa_id:
                    referencedColumnName: id
            inverseJoinColumns:
                answer_id:
                    unique: true
                    referencedColumnName: id
        typeSearches:
            targetEntity: TypeSearch
            joinTable:
                name: group_qa_type_searches
            joinColumns:
                group_qa_id:
                    referencedColumnName: id
            inverseJoinColumns:
                type_search_id:
                    referencedColumnName: id
    lifecycleCallbacks: {  }

文档http://doctrine-orm.readthedocs.org/en/latest/reference/association-mapping.html

第 5.6 节

【问题讨论】:

    标签: postgresql doctrine-orm


    【解决方案1】:

    我在“答案”和“问题”关联的 yaml 配置中有一个错误

    正确方法:

    manyToMany:
        questions:
            targetEntity: Question
            joinTable:
                name: group_qa_questions
                joinColumns:
                   group_qa_id:
                      referencedColumnName: id
                inverseJoinColumns:
                   question_id:
                      unique: true
                      referencedColumnName: id
        answers:
            targetEntity: Answer
            joinTable:
               name: group_qa_answers
               joinColumns:
                  group_qa_id:
                     referencedColumnName: id
               inverseJoinColumns:
                  answer_id:
                     unique: true
                     referencedColumnName: id
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多