Habtm Find Field At Join Table

Model Posts.php Relation:


'users' => array(self::MANY_MANY, 'Users', 'users_posts(post_id, user_id)'),

Find:


$criteria = new CDbCriteria();

$criteria->with=array('users'=>array('on'=>'users.created<:datetime')); // Problem HERE.

$criteria->params=array(':datetime'=>date('Y-m-d H:i:s'));

$event = Posts::model()->findByAttributes(array('id'=>$postid), $criteria);

Problem: I would like to find the CREATED field on the HABMT users_posts table and not on the users table as its doing.

How can I do that?

Hi,

You may try this




$criteria->with=array('users');

$criteria->condition='users_users.created<=:datetime';



Just curious, what are you trying to achieve by findByAttributes(array(‘id’=>$postid), $criteria)) ?