Doctrine2 oneToMany 关系 yaml

发布于 2024-10-16 08:04:14 字数 527 浏览 3 评论 0原文

我有一个名为“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

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 those options $object->getParent() (single object) and $object->getChildren() (collection of objects) .
Hope someone can help, thnx

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅暮の光 2024-10-23 08:04:14

您正在尝试进行一对多、自引用,应该是这样的:

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

看看手册 关联映射

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文