I’m trying to fetch data from the database with an innerjoin and criteria. I want to have al the result of the users and the videos.
For now i’m using the createCommand:
public function getRelatedByUser($users_id){
$videos = Yii::app()->db->createCommand()
->select('*')
->from('videos')
->join('users', 'videos.users_id = users.id')
->where('videos.users_id = :userId AND Active=:active'
, array(':userId' => $users_id, ':active' => TRUE))
->order('Date desc')
->limit(5)
->queryAll();
return $videos;
}
But i want to use the command with the yii model like:
public function getRelatedByUser($users_id){
$criteria=new CDbCriteria;
$criteria->select = '*';
$criteria->alias = 'videos';
$criteria->join = 'INNER JOIN users ON videos.users_id = users.id';
$criteria->condition = 'users.id = :userID AND Active=:active';
$criteria->params = array (
':userID' => $users_id,
':active' => TRUE,
);
return Videos::model()->findAll($criteria);
}
But the problem is, when i use the code above, i get only the values of Videos, because i use the Videos::model()…
Now i was wondering of there’s away to use multiple models, something like:
return VideosAndUsers::model()->findAll($criteria); or return All::model()->findAll($criteria);
please some help