Reputation: 433
I'm using Symfony 2.3 framework.
I am trying to create a system that will allow me to easily create tree menu (with root and child).
This field allows to show whether it is a root or child (id of this entity another record).
Now I want to do something like relation OneToMany but I don't know how. It is possibility to create relation with this same entity?
I thing about create method 'getChildren' in this entity but I don't know what operation I should to do.
Example:
and records in db: 1 category_1 0 2 subcategory_1 1 3 subcategory_2 1 etc.
Upvotes: 1
Views: 2071
Reputation: 2191
I think there is even an example in the doctrine documentation: http://docs.doctrine-project.org/en/latest/reference/association-mapping.html#many-to-many-self-referencing
But if you really want to build a Tree you could also consider the TreeExtension which uses a slightly different database model, which is a little bit more performant: https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/tree.md
Upvotes: 1