If this forum disapproves of reviving months-old threads then I apologize.
I believe I’m having the same issue as Damian. The SQL I’m getting simply isn’t what it needs to be and it seems like CSort is ignoring the alias relational option:
meanpenguin’s post seems to be close to the heart of the matter, but where would the ‘with’ option get set and on what object? It seems like the relations are meant to take care of this need. My code follows, and any suggestions are appreciated:
In GameStub Model:
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_merge(
array(
'game' => array( self::BELONGS_TO, 'Game', 'game_id', 'alias' => 'Game' ),
),
parent::relations()
);
}
Note that the array_merge is part of an implementation of an extension of CActiveRecord that I made, which GameStub extends - it should have no effect on how relations work and has proven not to thus far.
in GameStubController:
public function actionIndex()
{
// Select only entries that are for our $model
$oCriteria = new CDbCriteria( array(
//'condition' => '',
//'order' => 'time ASC',
)
);
$oSorter = new CSort('GameStub');
$oSorter->separators = array(':','-');
$oSorter->attributes = array(
'priority' => 'priority',
'desired_pct' => 'desired_pct',
'confidence_pct' => 'confidence_pct',
'biz_status' => 'biz_status',
'boots' => 'boots',
'addendum' => 'addendum',
'name' => 'game.name'
/*
'name' => array(
'asc' => 'game.name ASC',
'desc' => 'game.name DESC',
'label' => 'Title',
),
'metascore' => array(
'asc' => 'game.metascore ASC',
'desc' => 'game.metascore DESC',
'label' => 'MetaCritic Rating',
),
*/
);
$oSorter->multiSort = false;
$oSorter->defaultOrder = array( 'priority' => true );
// Create the data provider for the view
$oDataProvider = new CActiveDataProvider( 'GameStub',
array(
'pagination' => false,
'criteria' => $oCriteria,
'sort' => $oSorter,
));
$this->render( 'index', array(
'dataProvider' => $oDataProvider,
'oSorter' => $oSorter,
));
}
And finally, in my view:
echo $oSorter->link( 'name' );
$this->widget('application.extensions.nlistview.NListView', array(
'dataProvider' => $dataProvider,
'itemView' => '_stub',
'itemsCssClass' => 'listView',
'sItemsContainerTag' => 'ul',
'template' => '{summary}{sorter}{pager}{items}{pager}',
'enableSorting' => true,
'sortableAttributes'=>array(
'priority',
'desired_pct',
'confidence_pct',
'biz_status',
'boots',
'addendum',
'name',
//'GameStub.metascore',
),
));