Need Help In Yii To Display Two Tables Data In Cgridview?

Need help in yii to display two tables data in CGridView -

Tables Info -




1. Branch


Id

branch_name




2. User


Id

branch_id

user_name

BranchMaster


public function relations()

  {


    return array(

	'users' => array(self::HAS_MANY, 'User', 'branch_id'),	

	);

   }



UserMaster


public function relations()

  {


    return array(

	'branchs' => array(self::HAS_MANY, 'Branch', 'Id'),	

	);

   }

view.php


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

   array(

      'id'=>'my-grid',

      'dataProvider'=>$dataProvider,

      'filter'=>$model,

      'columns'=>array(

        'Id',

	'branch_name', 

	array('name'=>'users.user_name', 'value'=>$data->User>user_name),

        ),

));

_view.php


<b><?php echo CHtml::encode($data->getAttributeLabel('Id')); ?>:</b>

<?php echo CHtml::encode($data->Id); ?>

<br />

    

<b><?php echo CHtml::encode($data->getAttributeLabel('branch_name')); ?>:</b>

<?php echo CHtml::encode($data->branch_name); ?>

<br />

    

<b><?php echo CHtml::encode($data->getAttributeLabel('user_name')); ?>:</b>

<?php echo CHtml::encode($data->user_name); ?>

<br />

I’m getting records fine but user_name always blank value display.

Help me to solve my issue… thanks in advanced

[Solved]

Just change the relation HAS_ONE instead of HAS_MANY


'users' => array(self::HAS_ONE, 'User', 'branch_id'),

Working fine now!!

[twitter]rohisuthar[/twitter]