title: Yii CGridView sorting and searching with relation table
body: <p>I have 3 tables in my database,</p>
  
  <p>Image is below, I have followed <a href="http://www.yiiframework.com/wiki/281/searching-and-sorting-by-related-model-in-cgridview/" rel="nofollow noreferrer">http://www.yiiframework.com/wiki/281/searching-and-sorting-by-related-model-in-cgridview/</a></p>
  
  <p>to get final grid with with search and sort purpose. so i have connected 2 tables in <code>search()</code> function like </p>
  
  <blockquote>
  <pre><code>  public function search()
    {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.
  
        $criteria=new CDbCriteria;
  
                  $criteria-&gt;with = array( 'bposite' );
                  $criteria-&gt;together = false;
                  $criteria-&gt;with = array( 'client' );
        $criteria-&gt;compare('id',$this-&gt;id);
  //        $criteria-&gt;compare('client_id',$this-&gt;client_id);
  //        $criteria-&gt;compare('bposite_id',$this-&gt;bposite_id);
        $criteria-&gt;compare('userid',$this-&gt;userid,true);
        $criteria-&gt;compare('password',$this-&gt;password,true);
                  $criteria-&gt;compare( 'bposite.name', $this-&gt;bposite_search, true );                
                  $criteria-&gt;compare( 'client.name', $this-&gt;client_search, true );
  
  
        return new CActiveDataProvider($this, array(
            'criteria'=&gt;$criteria,
                              'sort'=&gt;array(
                                  'attributes'=&gt;array(
                                      'client_search'=&gt;array(
                                          'asc'=&gt;'client.name',
                                          'desc'=&gt;'client.name DESC',
                                      ),
                                      'bposite_search'=&gt;array(
                                          'asc'=&gt;'bposite.name',
                                          'desc'=&gt;'bposite.name DESC',
                                      ),
                                      '*',
                                  ),
                              ),
        ));
    }
  }
  </code></pre>
  </blockquote>
  
  <p>But I am getting result for client, bposite seach and sort is showing problem like </p>
  
  <pre><code>&gt;     Error 500: &lt;h1&gt;CDbException&lt;/h1&gt;
  &gt;     &lt;p&gt;CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'bposite.name'
  &gt; in 'where clause'. The SQL statement executed was: SELECT
  &gt; COUNT(DISTINCT `t`.`id`) FROM `clientbposites` `t`  LEFT OUTER JOIN
  &gt; `client` `client` ON (`t`.`client_id`=`client`.`id`)  WHERE
  &gt; (bposite.name LIKE :ycp0)
  &gt; (D:\wamp\www\yi\framework\db\CDbCommand.php:516)&lt;/p&gt;&lt;pre&gt;#0
  &gt; D:\wamp\www\yi\framework\db\CDbCommand.php(411):
  &gt; CDbCommand-&gt;queryInternal('fetchColumn', 0, Array)
  
  how can implement non-related table with cgridview search and sort options.
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/t3Vjn.jpg" alt="My database table and result girdview"></p>