簡體   English   中英

Doctrine2 oneToMany關系Yaml

[英]Doctrine2 oneToMany relation yaml

我有一個稱為“對象”的實體,這是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()(對象集合)。 希望有人可以幫助,謝謝

您正在嘗試進行一對多的自我引用,應該是這樣的:

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

看一下手動關聯映射

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM