I find the documentation very poor when it comes to explaining the creation of relationships between entities. So, i’ll have to ask for help to my fellow StackExchangers. So, i’m trying to build the following cases:
Case 1
A User belongs to one or more Group, and a Group can have many Permission. A User also can have a Permission.
Case 2
A Ticket has a Category, multiple Tag and multiple Comment.
Thanks in advance!
Sure thing. First thing to understand is that there is no “one way” to do this. Doctrine gives a lot of flexibility in terms of how you define the relationship – even if multiple definitions produce the exact same DDL (and this is important to understand – some of the mapping choices only effect the object-side of the ORM, not the model-side)
Here’s your Users/Groups/Permissions example, which are actually all many-to-many associations (I excluded all non-relevant but required code, like PK column definition)
If you have questions about what’s going on here, let me know.
Now, to your second example
As before, let me know if you want any of this explained.
P.S. None of this was actually tested, I just kinda banged it out in my IDE real fast. There might be a typo or two 😉