Yii order/search related model in bootstrap.widgets.TbGridView
there is 3 tables article, author and university
I'm making a grid for table article. Every article belongs to one author
and every author belongs to one university. I need to show University.name
| Author.name | Article.*
At admin view
$gridWidget=$this->widget('bootstrap.widgets.TbGridView',array(
'id'=>'dados-cd-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'author_name'=>array(
'name' => 'author_name',
'value' => '$data->author->name'
),
'university_name'=>array(
'name' => 'university_name',
'value' => '$data->university->author->nome'
),
...
array(
'class'=>'bootstrap.widgets.TbButtonColumn',
),
),
));
And at article model I have
public $author_name;
public $university_name;
public function rules()
{
...
return array(
array('author.name, university.name, ... , 'safe', 'on'=>'searc
h'),
...
);
}
public function search()
{
$criteria=new CDbCriteria;
$criteria->with = array( 'author','author.university' );
$criteria->compare('author.name',$this->author_name,true);
$criteria->compare('university.name',$this->university_name,true);
...
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
'sort'=>array(
'attributes'=>array(
'author_name'=>array(
'asc'=>'author.name',
'desc'=>'author.name DESC',
),
'university_name'=>array(
'asc'=>'university.name',
'desc'=>'university.name DESC',
),
'*',
),
),
));
}
The grid is working perfect fine. However when I try to search or order by
author_name I got a error message. I'll try to translate the error message
from portuguese but I don't know if it is like that in english: "Undefined
table:7 Error: missing entry for table author"
The funny part is that the university search and order is working just
fine. And I can't see the diference between they.
Anyone can help me?
No comments:
Post a Comment