I’m wondering if there’s better way than just the query it self.
I have a structure like this.
- characters
- character_section
- sections
- section_user
- users
And for characters and sections, they are many to many. Same for sections and users.
That means there are intermediate tables between characters, sections, and sections, users.
What I need is a known chapter, get all the sections and check if this section_user exist. Of course, we know the user_id.
[
{
“characer_id”: 1,
…
“sections”: {
“section_id”: 1,
…
“is_user_existed”: 1 //if the section_user existed
}
}
]
I tried to add belongsToMany in models. But not sure how to combine them together and check if the section_user record existed.