Doctrine2 oneToMany 关系 yaml
我有一个名为“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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在尝试进行一对多、自引用,应该是这样的:
看看手册 关联映射
You're trying to do One-to-Many, self referencing, it should be something like that:
Take a look at the manual Association Mapping