Accessing Data From Another Model In Cgridview

I have Golub.php and this relation


	public function relations()

	{

		// NOTE: you may need to adjust the relation name and the related

		// class name for the relations automatically generated below.

		return array(

			'relationPopisGolubova' => array(self::HAS_ONE, 'PopisGolubova', 'IDgolub'), 

		);

	}







and PopisGolubova.php


	public function relations()

	{

		// NOTE: you may need to adjust the relation name and the related

		// class name for the relations automatically generated below.

		return array(

			'iDgolub' => array(self::BELONGS_TO, 'Golub', 'IDgolub'),

		);

	}


	public function attributeLabels()

	{

		return array(

			'ID' => 'ID',

			'IDkorisnik' => 'Idkorisnik',

			'IDgolub' => 'Golub',

			'IDmajka' => 'Majka',

			'IDotac' => 'Otac',

			'IDleglo_natjecateljski' => 'Idleglo Natjecateljski',

			'IDleglo_uzgojni' => 'Idleglo Uzgojni',

		);

	}



And when I try to access variable "IDotac" from model PopisGolubova in admin.php which belongs to Golub model I do it like this




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

	'id'=>'golub-grid',

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

	'filter'=>$model,

	'columns'=>array(

                //...some other variables from Golub model

		array

		(

			'name'=>'relationPopisGolubova.IDotac',


		array(

			'class'=>'CButtonColumn',

		),

	),

)); 

It returns good values, but problem is that values are numbers, I need to check those number for real string values.

When I try to test it and just make value like this:


		array

		(

			'name'=>'relationPopisGolubova.IDotac',

			'value'=>'$data->relationPopisGolubova->IDotac',

		),

But problem is it says: Trying to get property of non-object

My guess is that some of your Golub records don’t have a matching related PopisGolubova record.

In such a case a HAS_ONE relation will return NULL.

You could try:




        array

        (

                'name'=>'relationPopisGolubova.IDotac',

                'value'=>'isset($data->relationPopisGolubova) ? $data->relationPopisGolubova->IDotac : ""',

        ),