title: Yii: How to Fetch data from mutiple models with criteria?
body: <p>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.</p>
  
  <p>For now i'm using the createCommand:</p>
  
  <pre><code>public function getRelatedByUser($users_id){
  
        $videos = Yii::app()-&gt;db-&gt;createCommand()
                          -&gt;select('*')
                          -&gt;from('videos')
                          -&gt;join('users', 'videos.users_id = users.id')
                          -&gt;where('videos.users_id = :userId AND Active=:active'
                          , array(':userId' =&gt; $users_id, ':active' =&gt; TRUE))                        
                          -&gt;order('Date desc')
                          -&gt;limit(5)
                          -&gt;queryAll();
  
                  return $videos;
         }
  </code></pre>
  
  <p>But i want to use the command with the yii model like:</p>
  
  <pre><code>public function getRelatedByUser($users_id){
  
                 $criteria=new CDbCriteria;  
                 $criteria-&gt;select = '*';
                 $criteria-&gt;alias = 'videos';
                 $criteria-&gt;join = 'INNER JOIN users ON videos.users_id = users.id';
                 $criteria-&gt;condition = 'users.id = :userID AND Active=:active';
                 $criteria-&gt;params = array (
                     ':userID' =&gt; $users_id,
                     ':active' =&gt; TRUE,
                 );                
                 return Videos::model()-&gt;findAll($criteria);
         }
  </code></pre>
  
  <p>But the problem is, when i use the code above, i get only the values of Videos, because i use the Videos::model()...</p>
  
  <p>Now i was wondering of there's away to use multiple models, something like:</p>
  
  <p><code>return VideosAndUsers::model()-&gt;findAll($criteria);</code> 
  <strong>or</strong> </p>
  
  <pre><code>return All::model()-&gt;findAll($criteria);
  </code></pre>