Something I realised today is the power of adding conditions to model relations. This allows you to specify which records are returned as part of the relationship, which therefore allows you to set up several relationships for different situations.
'users' => array(self::MANY_MANY, 'User', 'user2project(project_id, user_id)', 'condition' => 'accepted = 1'),
This only brings back users who have accepted an invitation.
I can then also set up a new relation, called ‘invitedUsers’ where the condition is the opposite.
This allows me to access the users easily:
$project = Project::model()->findByPk(1); $users = $project->users; $invitedUsers = $project->invitedUsers;