In grid how can I access the other table’s value.
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'activity-role-map-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'id',
'activity_id', # want to access the text, such as activities.activity
'role_id',
array(
'class'=>'CButtonColumn',
),
),
));
?>
In my interface there are three tables :
1) activities
- id integer
- activity text
2) roles
- id integer
- role text
3) activity_role_map
- id integer
- activity_id integer references activities (id)
- role_id integer references roles (id)
Relations created in the model files :
activities.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(
'id'=>array(self::HAS_MANY, 'activity_role_map', 'activity_id'),
);
}
roles.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(
'id'=>array(self::HAS_MANY, 'activity_role_map', 'role_id'),
);
}
activity_role_map.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(
'activity_id'=>array(self::BELONGS_TO, 'activities', 'activity'),
'role_id'=>array(self::BELONGS_TO, 'roles', 'id')
);
}
Error Thrown,
Property "activity_role_map.activities" is not defined, here it takes the activities as the column name.
How will I be able to list the name of the activity instead of id.