Let's suppose your model name is Restaurant.
If you are using ActiveRecord with rails, you may try this,
Restaurant.order('status, favorite DESC')
Frage
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,
Lösung
Let's suppose your model name is Restaurant.
If you are using ActiveRecord with rails, you may try this,
Restaurant.order('status, favorite DESC')