CGridView, search related table

How to use the Gridview to search in a related table? When i type in a country name en pres enter nothing will change. When i filter on a field within the model it wil show the corresponding items.

In my case i try to search on a country name when i’m in the City/Admin page.

Thank you in advanced.

Model City:


$criteria=new CDbCriteria;

$criteria->with=array('country');


$criteria->compare('id_city',$this->id_city);	

$criteria->compare('country.country',$this->country);

View Admin


<?php $this->widget('zii.widgets.grid.CGridView', array(

	'id'=>'city-grid',

	'cssFile'=>'/css/admin/gridview.css',

	'dataProvider'=>$model->search(),

	'filter'=>$model,

	'columns'=>array(

		'id_city',

		array(

            'name' => 'country',

            'value' => '$data->country->country',

        ),

		'province',

		'municipality',

		'city',

		array(

			'class'=>'CButtonColumn',

		),

	),

)); ?>

There’s a wiki for it

http://www.yiiframework.com/wiki/281/searching-and-sorting-by-related-model-in-cgridview/

@bennouna thank you! I forgot to add country to the safe on search rule…


array('country', 'safe', 'on'=>'search'),