相同表上的多个一对多关系原则

时间:2012-02-17 12:56:35

标签: symfony1 doctrine one-to-many

我对Doctrine和Yaml有一点问题:

这是我的模特:

 Keyword:
  columns:
    word: { type: string, notnull: true }
    is_stopword: { type: boolean, default: 0 }
    has_parents: { type: boolean, default: 0 }

Relation:
  columns:
    child: { type: integer, notnull: true }
    parent: { type: integer, notnull: true }
  relations:
    Keyword: { onDelete: CASCADE, local: [child, parent], foreign: id }    

不知怎的,我无法让Doctrine绑定两个关系,只有第一个(孩子)连接到“Keyword”...因为一个孩子可以有很多父母,一个父母很多孩子,这是唯一的我认为解决这个问题的方法......任何一个tipps?

1 个答案:

答案 0 :(得分:1)

您必须定义两个关系,一个用于父级,一个用于子级。 这个local: [child, parent]不会起作用,对于每个关系,你必须定义一个本地和一个外地。

Relation:
  columns:
    child: { type: integer, notnull: true }
    parent: { type: integer, notnull: true }
  relations:
    ChildKeyword: { onDelete: CASCADE, local: child, foreign: id }
    ParentKeyword: { onDelete: CASCADE, local: parent, foreign: id }
相关问题