I've added a priority
value to sort a list of objects in ascending order. The value is optional on records, and in the production app there are a lot of records that exist where priority
is null.
When I sort the list, it returns all the nulls first -- the expected behaviour should be to include the nulls last, sorted by created_at desc.
@company.spark_sessions.order('priority asc, created_at desc')
Is there a nice, standard Rails way to return null records at the end of the list?
The top comment on a thread from five years ago recommended adding arrays together to preserve order, which I'm not fond of.