gpt4 book ai didi

php - Doctrine2 oneToMany 关系 yaml

转载 作者:行者123 更新时间:2023-11-29 01:46:47 25 4
gpt4 key购买 nike

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

最佳答案

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

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

关于php - Doctrine2 oneToMany 关系 yaml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4920177/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com