I have three tables - myusers, organisation_classrooms, organisation_classrooms_myusers (this is a pivot table between organisation_classrooms & the myusers table)
organisation_classrooms(classroom_id, organisation_id, title)
organisation_classrooms_myusers(classroom_id, user_id)
myusers(user_id, organisation_id, fullname)
I have the following search() function within one of my models:
return new CActiveDataProvider(OrganisationClassroom::model()->currentUserOrganisation(), array(
'criteria' => $criteria,
'pagination' => array(
'pageSize' => 10,
)
));
This is the dataset that I am using
organisation_classrooms
classroom_id title organisation_id
1 Class A 37383
2 Class B 37383
3 Class C 37383
organisation_classrooms_myusers
classroom_id user_id
2 1558
3 1558
myusers
user_id organisation_id name
1558 37383 Bob Doe
I’d like to amend the model so that for each organisation_classroom that belongs to the organisation, check if the user_id 1558 exists in the organisation_classrooms_myusers pivot table and basically set a boolean value
e.g
I’d like the following data returned via the organisation_classrooms CActiveDataProvider used above for the user_id of 1558
classroom_id title organisation_id pivot_set
1 Class A 37383 0
2 Class B 37383 1
3 Class C 37383 1
Can anyone suggest how to go about this? This way I will be able to do a sort_by pivot_set column ASC/DESC etc…
P.S I apologise for the formatting - the forum doesn’t seem to retain the spacing i added with the dataset stuff above