Active Record for Associative Table with extra field

I can not figure out the elegant way to use Active Record in the below database structure. The relation between tbl_user and tbl_family is MANY::MANY. (and other fields)


tbl_user_family.family_id (and other fields)

The tbl_user_family is an ordinary associative table, … except for the extra field active. is true when a user is actively working on a family.

I would like to elegantly chain AR to find the id for the active family for a user. It should look something like this:


How would I do this?

well i would like to know if any other elegant way exists but if i was there I would make a view table active_families which have user_id,family_id,status_id

here all are foreign keys from respective tables

Then from your user relation

$user-> active_families which would be list of all families that one is working on. ofcourse you can do CDbcriteria stuff to get conditional things

Not tested, but how about something like this:

‘active_family’=>array(self::HAS_MANY, ‘Family’, ‘family_id’,‘condition’=>‘active=1’)