title: Yii - Joining multiple tables
body: <p>i am trying to join 3 tables in my model</p>
  
  <pre><code>trx_evaluation_details
  
  trx_evaluation
  
  rm_projects
  </code></pre>
  
  <p><code>trx_evaluation_details</code> and <code>trx_evaluation</code> are already joined by using the relation function in my model.</p>
  
  <pre><code>'eval' =&gt; array(self::BELONGS_TO, 'Evaluation', 'eval_id'),
  </code></pre>
  
  <p>i am trying to join the <code>rm_projects</code> table so that i can access the <code>project_name</code> column in that table so i added this.</p>
  
  <pre><code>'project' =&gt; array(self::BELONGS_TO, 'RmProjects', 'project_id'),
  </code></pre>
  
  <p>so i have this relation in my model..</p>
  
  <pre><code>public function relations() {
          return array(                
              'eval' =&gt; array(self::BELONGS_TO, 'Evaluation', 'eval_id'),
              'project' =&gt; array(self::BELONGS_TO, 'RmProjects', 'project_id'),
          );
      }
  </code></pre>
  
  <p>i tried to access it like this..</p>
  
  <pre><code>if ($search_date_end !== '' &amp;&amp; $search_date_start !== '' &amp;&amp; $search !== '') {
                      $criteria-&gt;condition = "start_date  &gt;= '$search_date_start' 
                      AND end_date &lt;= '$search_date_end' 
                      AND project.project_name like '%$search%'
                      AND t.employee_id = '$employee-&gt;company_id'"; 
              }
  </code></pre>
  
  <p>where i tried project.project_name.. but it is returning an error</p>
  
  <blockquote>
    <p>CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]:
    Column not found: 1054 Unknown column 'project.project_name' in 'where
    clause'. The SQL statement executed was: SELECT COUNT(DISTINCT
    <code>t</code>.<code>id</code>) FROM <code>trx_evaluation_details</code> <code>t</code> LEFT OUTER JOIN
    <code>trx_evaluation</code> <code>eval</code> ON (<code>t</code>.<code>eval_id</code>=<code>eval</code>.<code>id</code>) WHERE
    (start_date >= '2015-11-01' AND end_date &lt;= '2015-12-01' AND
    project.project_name like '%sprobe%'AND t.employee_id = '120069')</p>
  </blockquote>
  
  <p>which means that it cannot see <code>project.project_name</code> and the table rm_projects is not joined in the returned error.</p>
  
  <p>how can i access the project_name and how can i join the <code>rm_projects</code> table.?
  please help.</p>