Cgridview Search On Relation Name

Hi guys.

First: i have googled this, and found endless ammount of forum-threads and tutorials, but i still cant seem to make it work.

I have a model called Wine. That has its country and region represented by a id.

I want the gridview to generate the region and country names, and allso the filterboxes to respond if you write the country or region name.

In my model:


public function relations()

	{

		return array(

				'GetRegion' => array(self::BELONGS_TO, 'Region', 'region', 'alias' => 'r'),

				'GetCountry' => array(self::BELONGS_TO, 'Country', 'country', 'alias' => 'c'),

		);

	}



My Controller:


	public function actionIndex()

	{

		$model=new Wine('search');

		$model->unsetAttributes();  // clear any default values

		if(isset($_GET['Wine']))

			$model->attributes=$_GET['Wine'];

		$this->render('index', array(

				'model'=>$model,

				));

	

	}

And my view:


<?php 

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

	'id'=>'wine-grid',

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

	'filter'=>$model,

	'columns'=>array(

		'name',

		'region',

		'country',

		'year',

	),

)); ?>

Ive tried with r.name/c.name and with $data->GetRegion->name, but errormessage on both.

Anyone have any inputs? Ive been stuck for hours :confused:

Thanks in advance!

Update:

Viewfile:


	'columns'=>array(

		'name',

		'GetRegion.name',

		'GetCountry.name',

		'year',

		'GetReview.score'

Works, but the filterboxes disapear.

Tried Model:


		$criteria->compare('GetRegion.name',$this->region);

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

Does not help.

Ah, yes, it seems "endless". Partly because of the lack of an official tutorial on this matter, many people have some difficulty in using CGridView and CActiveDataProvider.

The most useful document on this topic, IMO, is a wiki named "Searching and sorting by related model in CGridView".

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

It has been proved to be useful by many people. Please read it carefully, the answer is there.

Thank you, kindly.