And when i am trying to set the sort order of this relation dynamically either by
$activity_model=Activity::model()->with(array('members'=>array('order'=>'members.LastName DESC')))->findbyPk($activity_id);
or via
$activity_model=Activity::model()->findbyPk($activity_id);
$members=$activity_model->members(array('order'=>'members.LastName DESC'));
I get a sql query with this sort order
ORDER BY members.LastName ASC, members.LastName DESC
In this case the sort order of the relation wouldn’t be overwriten like mentioned here
Or is something wrong with my code? I remember I have to set the alias for the many_many relation to be able to add sorting orders otherwise the columns wouldn’t be found which ends in a sql error.
I had the same problem. I solved it simply by removing the order clause, in the model, in the definition of the relation. The order clause should only appear in the with() function, otherwise the order clause in the definition of the relation override it.