sql - How to sort and return records with a given value in a given field last in Rails? -
class foo < activerecord::base end foo.order( status: :on_hold ...? how order foos status of on_hold returned last?
ror 4. postgres.
it work :
foo.order( "status = 'on_hold', status") a quick test on postgresql boolean ordering :
app=# select * test1; | b ---+--------- t | sic est f | non est (2 rows) app=# select * test1 order a; | b ---+--------- f | non est t | sic est (2 rows) app=# well @muistooshort said, can :
foo.order("case status when 'on_hold' 1 else 0 end, status")
Comments
Post a Comment