I have 3 tables in my database,
Image below, I followed http://www.yiiframework.com/wiki/281/searching-and-sorting-by-related-model-in-cgridview/
to get the final grid for the purpose of searching and sorting. so I connected 2 tables in a function search()e.g.
public function search()
{
$criteria=new CDbCriteria;
$criteria->with = array( 'bposite' );
$criteria->together = false;
$criteria->with = array( 'client' );
$criteria->compare('id',$this->id);
$criteria->compare('userid',$this->userid,true);
$criteria->compare('password',$this->password,true);
$criteria->compare( 'bposite.name', $this->bposite_search, true );
$criteria->compare( 'client.name', $this->client_search, true );
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
'sort'=>array(
'attributes'=>array(
'client_search'=>array(
'asc'=>'client.name',
'desc'=>'client.name DESC',
),
'bposite_search'=>array(
'asc'=>'bposite.name',
'desc'=>'bposite.name DESC',
),
'*',
),
),
));
}
}
But I get the result for the client, bposite seach and sort show a problem like
> Error 500: <h1>CDbException</h1>
> <p>CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'bposite.name'
> in 'where clause'. The SQL statement executed was: SELECT
> COUNT(DISTINCT `t`.`id`) FROM `clientbposites` `t` LEFT OUTER JOIN
> `client` `client` ON (`t`.`client_id`=`client`.`id`) WHERE
> (bposite.name LIKE :ycp0)
> (D:\wamp\www\yi\framework\db\CDbCommand.php:516)</p><pre>
> D:\wamp\www\yi\framework\db\CDbCommand.php(411):
> CDbCommand->queryInternal('fetchColumn', 0, Array)
how can implement non-related table with cgridview search and sort options.

source
share