【问题标题】:Doctrine2 oneToMany relation yamlDoctrine2 oneToMany 关系 yaml
【发布时间】:2011-06-22 15:41:51
【问题描述】:

我有一个名为“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() (single object) 和 $object->getChildren() (collection of objects) 。 希望有人可以帮忙,thnx

【问题讨论】:

  • 所以你想要一个自引用关系,比如电子商务网站中的一个类别如何可以有一个父类别和多个子类别?
  • IMO,你不应该过多考虑它在数据库中的外观......让 Doctrine 去做吧!

标签: php mysql yaml doctrine-orm


【解决方案1】:

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

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

【讨论】:

  • 在阅读了更多关于文档的内容后发现了它。反正thnx很多
猜你喜欢
  • 2013-08-20
  • 1970-01-01
  • 2013-05-22
  • 1970-01-01
  • 2011-12-29
  • 1970-01-01
  • 1970-01-01
  • 2018-02-10
  • 1970-01-01
相关资源
最近更新 更多