title: Yii CActiveDataProvider Relations
body: <p>Anyone can enighten me, i am new to Yii. I have 3 tables</p>
  
  <pre><code>projects      (id,name,status,created_by)
  users         (id,name)
  project_users (id,project_id,user_id)
  </code></pre>
  
  <p>The condition is: Show all projects if created by current user or current user is a project member. I have already a working code for this.</p>
  
  <pre><code>    $criteria=new CDbCriteria;
      $criteria-&gt;join = ' LEFT JOIN project_users pu ON pu.project_id=t.id';
      $criteria-&gt;addCondition('created_by='.Yii::app()-&gt;user-&gt;id.' OR pu.user_id='.Yii::app()-&gt;user-&gt;id);
      $criteria-&gt;distinct = true;
  
      $dataProvider=new CActiveDataProvider('Project',
      array(
              'pagination'=&gt;array('pageSize'=&gt;15),
              'criteria'=&gt; $criteria
          )
      );
  </code></pre>
  
  <p>But, id like to learn how can i get same result using "WITH" (relational AR query in Yii). I already tried but all failed. Please help thanks.</p>