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 tho开发者_运维技巧se options $object->getParent() (single object) and $object->getChildren() (collection of objects) . Hope someone can help, thnx
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
精彩评论