title: Searching and sorting by related model in CGridView Yii
body: <p>I want to make my CGridView columns searchable after reading <a href="http://www.yiiframework.com/wiki/281/searching-and-sorting-by-related-model-in-cgridview" rel="nofollow">this</a> the problem is when i use one <code>cdbCriteria-&gt;with</code> condition it works fine. But It gives an error when i add more than one <code>cdbCriteria-&gt;with</code> condition. More specifically I am pasting my code here.</p>
  
  <pre><code>           $criteria=new CDbCriteria;
             $criteria-&gt;with = array( 'teacherGradeSection','course'  );
             $criteria-&gt;with = array( 'teacherGradeSection','teacher' );
             $criteria-&gt;together = true;
             $criteria-&gt;compare('course.name', $this-&gt;course_search, true );
             $criteria-&gt;compare('teacher.firstname', $this-&gt;teacher_search, true );
  </code></pre>
  
  <p>When i use only one with condition it works fine but gives an error when more than one with condition is used.
  <br><br>
  <strong>Error</strong></p>
  
  <pre><code>SQLSTATE[42S22]: Column not found: 1054 Unknown column
  </code></pre>
  
  <p>Edit 1:
  These are the available relations</p>
  
  <pre><code>public function relations()
  {
      // NOTE: you may need to adjust the relation name and the related
      // class name for the relations automatically generated below.
      return array(
          'submissions' =&gt; array(self::HAS_MANY, 'Submission', 'task_id'),
          'teacherGradeSection' =&gt; array(self::BELONGS_TO, 'TeacherGradeSection', 'teacher_grade_section_id'),
          'course'    =&gt; array(self::HAS_MANY, 'Course', array('course_id'=&gt;'id'),'through'=&gt;'teacherGradeSection'),
           'teacher'=&gt;  array(self::HAS_MANY,'Teacher',array('teacher_teacher_id'=&gt;'teacher_id'),'through'=&gt;'teacherGradeSection'),
     ); }
  </code></pre>
  
  <p><br>
  As suugested by @Nisic and @Noam148 when i use <br> <code>$criteria-&gt;with=array('teacherGradeSection','course','teacher ')</code>
  I got the following error</p>
  
  <pre><code>CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: Syntax error or access violation: 1066 Not unique table/alias: 'teacherGradeSection'. The SQL statement executed was: SELECT COUNT(DISTINCT `t`.`id`) FROM `task` `t` LEFT OUTER JOIN `teacher_grade_section` `teacherGradeSection` ON (`t`.`teacher_grade_section_id`=`teacherGradeSection`.`id`) LEFT OUTER JOIN `course` `course` ON (`course`.`id`=`teacherGradeSection`.`course_id`) LEFT OUTER JOIN `teacher_grade_section` `teacherGradeSection` ON (`t`.`teacher_grade_section_id`=`teacherGradeSection`.`id`) LEFT OUTER JOIN `teacher` `teacher` ON (`teacher`.`teacher_id`=`teacherGradeSection`.`teacher_teacher_id`)
  </code></pre>