Can I somehow define in ORM model has_many relation to sort related records like this:
SELECT * FROM tablename ORDER BY -position DESC
I have table departments which has many users. I would like to sort users within department by sort_order field. This field can be either number or NULL. I would like to have NULLs at the end of the list. MySQL has a syntax by sorting nulls at the end by adding "-" before sorting field name and using DESC. Taken from here: http://stackoverflow.com/questions/2051602/mysql-orderby-a-number-nulls-last
As the stackoverflow post already mentions, what you do is
SELECT * FROM tablename ORDER BY (0 - position) DESC
Which is ordering by a dynamic expression. You could try to get this in with a DB::expr(), but you can't define that as part of the property, and I'm not sure it will work there.