CGridView with has_many

hai all,

i have tabel

person


id

name

‘hasphone’ => array(self::HAS_MANY, ‘Phones’, ‘person_id’)

phone


id

person_id

number

i want to display data in grid like this




$this->widget('bootstrap.widgets.BootGridView', array(

	'id'=>'person-grid',

	'itemsCssClass'=>'table table-striped table-condensed',

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

	'htmlOptions'=>array('style'=>'width: 95%'),

	'columns'=>array(

    array('name'=>'name', 'header'=>'Name'),	

    array('name'=>'phone', 'header'=>'Phone', 'value'=> '<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />???'),

		array(

			'class'=>'bootstrap.widgets.BootButtonColumn',

      'header'=>'Action',           

      'htmlOptions'=>array('style'=>'width: 50px'),			

		),

	),

)); 



any person likely has a lot of numbers, and I just want to display only the first telephone number in the grid

Can anyone help me?

if you talk to logic

if hasphone?

grab the first record and show

else

if no show "no number"

how do I check hasphone?

if the condition HAS_ONE $data->hasphone? bala … blah : blah … blah

this work well

but how if has_many ?

I guess this will do it:


array('name'=>'phone',

    'header'=>'Phone',

    'value'=> 'count($data->hasPhone) ? $data->hasPhone[0]->number : ""'),