I have a table where I'd like to get all id's that equal 26 first, then have the rest sorted in descending order, so something like:
row id
--- --
1 26
2 26
3 26
4 27
5 25
6 24
Would normally result in:
select id
from table
order by id=26 desc, id desc
How should I construct a find() in Cake? This is what I figure:
$this->Model->find('all', array(
'conditions' => array('Model.id' => 26),
'order' => array('Model.id' => 'DESC')
));
But how should I tell Cake to retrieve the rest of the id's and sort them in descending order after retrieving all id's that equal 26?
Try this.
$this->Model->find('all', array(
'order' => array('Model.id = 26 DESC' , 'Model.id DESC')
));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With