Let's suppose your model name is Restaurant.
If you are using ActiveRecord with rails, you may try this,
Restaurant.order('status, favorite DESC')
题
How can I order by a field and its value? For example, say I have 10 records, of which:
status
is active
) and favorite
is true
status
is active
) and favorite
is false
status
is completed
) and favorite
is true
status
is completed
) and favorite
is false
How can I put the records in order as above? That is,
解决方案
Let's suppose your model name is Restaurant.
If you are using ActiveRecord with rails, you may try this,
Restaurant.order('status, favorite DESC')