Doctrine2 oneToMany关系yaml

时间:2011-02-07 10:27:13

标签: php mysql yaml doctrine-orm

我有一个名为“Object”的实体,这里是yaml代码:

Entities\Object:
  type: entity
  table: objects
  id:
    id:
      type: integer
      generator:
      strategy: AUTO
  fields:
    parent_id: 
      type : integer
  oneToOne:
    type:
      targetEntity: ObjectType
      joinColumn:
        name: type_id
        referencedColumnName: id

我想添加一个子父关系(oneToMany),但我不知道如何?我希望mysql表具有以下结构:id,type_id,parent_id和具有这些选项的实体$ object-> getParent()(单个对象)和$ object-> getChildren()(对象集合)。 希望有人可以提供帮助,thnx

1 个答案:

答案 0 :(得分:4)

你正在尝试一对多,自我引用,它应该是这样的:

Entities\Objects:
  type: entity
  table: objects
  id:
    id:
      type: integer
      generator:
        strategy: AUTO
  oneToMany:
    children:
      targetEntity: Objects
      mappedBy: parent
  manyToOne:
    parent:
      targetEntity: Objects
      inversedBy: children
      joinColumn:
        name: parent_id
        referencedColumnName: id

查看手册Association Mapping