Answer the question
In order to leave comments, you need to log in
How to implement a many-to-many relationship for the same table?
Hello dear experts!
I'm having a problem implementing a multi-level directory. There is a category entity, it has id, parent_id, name. The parent category does not know anything about the children. The question is, how do you introduce a parent to a child?
Nothing came to my mind except a many-to-many relationship. But how to implement this and is it even possible?
Sorry for the noob question.
Answer the question
In order to leave comments, you need to log in
What? Display all children whose parent is equal to the id of the parent, so you have a connection between the "parent" and the "daughters" ???
For a many-to-many relationship, create another table. In which there will be fields `parent` and `child`.
Display all children by parent id:
Display all parents by child id:
Naturally, the table should have an `id` field for convenient manipulation with it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question