Despite many searches, I’m desperately stuck with this point.
Here is the code :
model : AccountingEntry schema
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(
'thirdParty' => array(self::BELONGS_TO, 'ThirdParty', 'third_party_id'),
'account' => array(self::BELONGS_TO, 'Account', 'account_id'),
);
}
view : index with CGridView (simplified)
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $dataProvider,
'columns' => array(
'entry_date:date:Date',
'thirdParty.name:text:Tiers',
),
));
The second column is not clickable and does not accept sorting. After some post like this one I expected the sorting to work but it does not.
I tried to add a ‘with’ attribute to the CDataProvider like this :
controller : the actionIndex() method modified
$dataProvider = new CActiveDataProvider('AccountingEntry', array(
'criteria' => array(
'condition' => 'account_id=' . $activeAccountId,
'with' => array('thirdParty'),
'order' => 'entry_date ASC, updated_at ASC',
),
'pagination' => array(
'pageSize' => Yii::app()->params['accountingEntry']['pagination'],
),
));
Unfortunately, I have two issues here
1 - I’m using a sort attribute on this CDataProvider and it causes a CDbException :
I don’t know how I could declare aliases here to avoid this problem.
2 - Anyway, even if I remove the ‘sort’ attribute, the ‘Tiers’ column remains unclickable…
Any help is welcome