开发者

Doctrine2 oneToMany relation yaml

开发者 https://www.devze.com 2023-02-09 04:20 出处:网络
I have an entity called “Object”, here is the yaml code: Entities\\Object: type: entity table: objects

I have an entity called “Object”, here is the yaml code:

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

I want to add a children parent relation (oneToMany) but I don’t know how? I want the mysql table to have following structure: id, type_id, parent_id and the entity to have tho开发者_运维技巧se options $object->getParent() (single object) and $object->getChildren() (collection of objects) . Hope someone can help, thnx


You're trying to do One-to-Many, self referencing, it should be something like that:

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

Take a look at the manual Association Mapping

0

精彩评论

暂无评论...
验证码 换一张
取 消