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.
tbl_user.id (and other fields)
tbl_user_family.user_id
tbl_user_family.family_id
tbl_user_family.active
tbl_family.id (and other fields)
The tbl_user_family is an ordinary associative table, … except for the extra field active. tbl_user_family.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:
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