I've three DB tables for two objects with MANY-MANY relationship, as below
table user (id int, ......)
table subject (id int, usn int, ......)
table user_subject (user_id int, subject_id int, role int)
user_subject table links user and subject tables by foreign key user_id and subject_id.
I'd like to load all subjects associated with user 1 whose role as 1, and have usn between 1 to 20.
I use following code to do this:
$criteria = new CDbCriteria; $criteria->with = array('users'); $criteria->condition = "user_id=:userID AND role=1 AND usn>=:startUSN AND usn<=:endUSN"; $criteria->params = array(':userID' => 1, ':startUSN' => 1, ':endUSN' => 20); $subject = Subject::model()->findAll($criteria);
But the result I got for $subject is null.
Could anyone tell me where I did wrong?
Thanks for your time!