I have 4 tables (among a lot of others - just showing the relevant ones). They are:
- "users"
- id
- name
- role_id
- "roles"
- id
- name
- "chapter_role_view_permissions"
- id
- chapter_id
- role_id
- "chapters"
- id
- name
I'm trying to build a query that will return to me a list of all users, their role name, all chapters per user, and whether or not they have view access to each chapter. So lets say there are 2 users and 2 chapter. User 1 is role_id=1 and User 2 is role_id=2. And the chapter_role_view_permissions has 1 record ( id:1 | chapter_id: 1 | role_id: 1 ) which means only users with role_id=1 can view chapter 1.
The query result I am looking for should be something like:
|---users.id---|--roles.id---|---chapters.id--|-can_view_chapter-|
|------ 1 ------|----- 1 -------|------- 1 --------|----------- 1 -----------|
|------ 1 ------|----- 1 -------|------- 2 --------|----------- 0 -----------|
|------ 2 ------|----- 2 -------|------- 1 --------|----------- 0 -----------|
|------ 2 ------|----- 2 -------|------- 2 --------|----------- 0 -----------|
Any idea what the query might look like? I don't want to have to make a new field in chapter_role_view_permissions that says "allowed" and insert new records for each role type with either allowed=1 or allowed=0