Navin Navin - 3 months ago 7
Ruby Question

rails each order with nil value

In rails application I want to sort task by priority, the priority have the value p1,p2,p3,nil. If I sort like this

task..order(:priority).each do |t|
puts t
end


The task which have nil as priority comes first, then other things are sorted based on order. I want task which have nil priority to go last on loop. How to accomplish this one?

I am using mysql db

Answer
Task.order('priority IS NULL, priority DESC')