Reputation: 7182
I'm using Symfony 3.0.1 (doctrine/orm ^2.5) and I want to have a polymorphic relation on Forum entity to Category or Forum entities (as in the image). You can imagine it like a simple forum website example. You have got general category -> forum -> subforum -> subsubforum etc. What's the best way to do that?
Upvotes: 0
Views: 82
Reputation: 3483
You could have a look at nested sets in the doctrine extension. I've used them and found them very easy - they take care of a lot of the complications involved in handling nested set relationships. In your case Forum
would be be just annotated with @Gedmo\Tree(type="nested")
. Each forum would have a ManyToOne relation to Category
as well as a relation to its own parent forum.
https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/tree.md
Upvotes: 1