Cgridview With Multiple Models

Hi All.

I have the following 2 models with a 1 to many relationship. One Organisation can have multiple connections:

CPConnection has a column organisation_id which holds the primary key value of the Organisation id column.

Model CpOrganisation:




public function relations()

{

	return array('connection' => array(self::BELONGS_TO, 'cp_connection', 'id'),

	);

}



Model CpConnection:




public function relations()

{

	return array('organisation' => array(self::HAS_ONE, 'cp_organisation', 'organisation_id'),

	);

}



My view file:




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

	'id'=>'cp-connection-grid',

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

	'filter'=>$model,

		

	'columns'=>array('organisation_id','connection_type_id','server_name',

		

			array('name'=>'Organisation',

'value'=>'$data->organisation->organisation_name',

						'type'=>'raw'),




	),

)); ?>



I keep getting: htmlspecialchars() expects parameter 1 to be string, array given

Any idea what I am doing wrong?

Do I have to set up a relationship on database level?

Never mind, got it working. I created a relationship on database level and used Gii to set the relationship code on the model and all is working fine now.

Only other problem is that there is no filter option on the referenced column. How can I fix that? As per pic below.

5427

Capture.PNG