Following is the query to take all records from page table and respective access_level from role_page_access table, join together by page.id for a given roleid. $roleid is the parameter to this method.
$query = 'select p.*,t.access_level from page p '.
'left join (SELECT p.id,rpa.role_id,rpa.access_level FROM page p '.
'left join role_page_access rpa on rpa.page_id = p.id '.
'where rpa.role_id = ' . $roleid . ') as t on p.id = t.id';
Actually, I need to use this query for ignited datatables. But at least if I can convert this to active record, that will be very helpful.
Is there a way to just specify regular query in active records? Otherwise how to convert this to active records?
UPDATE: page table has pages and role_page_access table has mapping between userrole and page with an integer field "access_level" to specify have access or not. If there are no mapping also considered as no access.
I want all the records from page and matching access_level from role_page_access by pageid and given role. So there will be null access_level if no matching records found in mapping table.
I have to use this in $this->db or $this->datatables.