2015-09-03 79 views
0

我在yaml中使用了一對多,單向與聯接表關聯,但是在數據庫中沒有創建唯一約束。許多到許多關聯原則中的唯一列2

我使用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節

回答

0

我在「答案」和「問題」分組的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