I have four tables in my DB as shown(user, user_test, test, status). There is a M:M to relation between user and test and therefore user_test is a Gerund between them.
The status table has statuses for both user_test and test tables. The tablename field in status table shows which table the status belongs to as shown in the lower image.
I want to show table user_test in a CGridView with the related data in all the three tables user, test and status. All is well as the relations are correct.
Problem: When I want to show status.name in my CGrid like:
array(
'header'=>'Status',
'value'=>'$data->status->name',
),
It gives me name ‘completed’ but it is the status of table ‘test’ and the correct one should be ‘confirmed’ as status_id in user_test is 2.
Any help?
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->with=array('user','test','status');
$criteria->compare('id',$this->id);
$criteria->compare('user_id',$this->user_id);
$criteria->compare('test_id',$this->test_id);
$criteria->compare('status.id',$this->status_id);
$criteria->compare('bonus',$this->bonus);
$criteria->compare('user.signum',$this->signum, FALSE);
$criteria->compare('user.email',$this->email, FALSE);
$criteria->compare('test.seats',$this->seats, FALSE);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
'sort'=>array(
'attributes'=>array(
'signum'=>array(
'asc'=>'user.signum',
'desc'=>'user.signum DESC',
),
'email'=>array(
'asc'=>'user.email',
'desc'=>'user.email DESC',
),
'seats'=>array(
'asc'=>'test.seats',
'desc'=>'test.seats DESC'
),
'*',
),
),
));
}