grid view

hello Friends,

I have 3 tables




I want to display records in grid vieew

like all records from company_user + username from user table

in user model i have written this type of 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(

			'company_user'			=>array(self::HAS_ONE,'CompanyUser','user_id','select' =>array('first_name','status'),

											'with'=>array('company'=>array(self::BELONGS_TO, 'Company', 'company_id','joinType' => 'INNER JOIN')),


			'company_user_rel_only'	=>array(self::HAS_ONE,'CompanyUser','user_id','select' =>array('first_name', 'last_name')),



I dont know above code is write or wrong… :mellow:

plz help me soon

thanks in advance

I don’t know if it will help you, but if your database model seems ok to you (with foreign key constraint, …), you just have to generate your Yii model with gii, then you will be sure the Yii relations are corrects.

Relations for company_user model:

public function relations() {

	return array(

    	'user' => array(self::BELONGS_TO, 'user', 'user_id'),

    	'company' => array(self::BELONGS_TO, 'company', 'company_id'),



Then use CGridView

$dataProvider=new CActiveDataProvider('company_user');  $this->widget('zii.widgets.grid.CGridView', array( 	'dataProvider'=>$dataProvider,

    'columns' => array(

        array("name" => "first_name"),

        array("name" => "last_name"),

        array("name" => "user.user_name")