$users = Users::model()->findAll();
$user = Users::model()->findByPk($id);
class Users extends CActiveRecord
{
…
public function relations()
{
return array(
'messages'=>array(self::HAS_MANY, 'Messages', 'user_id')
);
}
}
$user->messages