Reputation: 2946
Using the Yii Framework, How can I sort the related model modifiervalues by "sortorder ASC, name ASC"? I have tried order->('modifiervalues.sortorder ASC, modifiervalues.name ASC')
to no avail
<?php
$item = Item::model()
->with("modifiergroups.modifiervalues")
->findByPk($id);
?>
Upvotes: 1
Views: 6835
Reputation: 3950
<?php
$item = Item::model()
->with(array('modifiergroups'=>array('order'=>'modifiervalues.sortorder ASC, modifiervalues.name ASC')))
->findByPk($id));
?>
You need to add base relation name in order also. Try this.
Upvotes: 0
Reputation: 2656
Try
$item = Item::model()
->with('modifiergroups')
->find(array(
'condition'=>'id = :id',
'params'=>array('id'=>$id),
'order'=>'modifiervalues.sortorder ASC, modifiervalues.name ASC'
)
);
or (I haven't actually tried this one, but it should work just the same)
$item = Item::model()
->with(array('modifiergroups'=>array('order'=>'modifiervalues.sortorder ASC, modifiervalues.name ASC')))
->findByPk($id));
Notes:
with
only a field, I don't think you can order by another field. You should give with
the name of the relation.order
methodUpvotes: 3