Let’s discuss example relationship given on following URL
http://www.yiiframework.com/doc/guide/1.1/en/database.arr
If you want to be able to filter results in grid using Posts’ author name then modify the search function of Post model to similar to the one given below.
public function search()
{
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id);
if(!intval($this->author_id) && is_string($this->author_id) && strlen($this->author_id) > 0) {
$criteria->with[]='user';
$criteria->addSearchCondition("user.name",$this->author_id,true);
}else{
$criteria->compare('author_id',$this->author_id);
}
return new CActiveDataProvider(get_class($this), array(
'criteria'=>$criteria,
'pagination' => array(
'pageSize'=>Yii::app()->params['defaultPageSize']
)
));
}