I have the following database tables and relationships:
users - 1 to many <- user_group -> many to 1 - groups
So in Yii i have 2 models, Users and Groups with a Many to Many relationship. My application requires a user to be able to see all the other users they have a relationship with. So a user may belong to several groups and I want to be able to see all of the users friends from all of their groups.
You may do $user->groups[$i]->users to traverse through the users within the same group of the primary user, but I guess that's not what you want. Probably you should write a plain SQL for such a problem and call findBySql().