I have a DataMapper class Song (through PostgreSQL) that has the following property:
property :rating, Float, :required => false
Users can rate songs. The problem is that I want users to browse available songs by rating. Say I have 5 songs, 3 of them have been rated, then something like this:
Song.all(:order => [:rating.desc])
will get me songs in the following order: {null, null, 10, 7, 6} or whatever. Is there a simple way to get these null values to the bottom of the ordering, so that my results will look like {10, 7, 6, null, null}.
I tried
Song.all(:rating.not => nil, :order => [rating.desc]) + song.all(:rating => nil)
but this combines the queries such that my resultset is nil.
An alternative of course is to default a null rating to something like -1, but due to some limitations I'd rather avoid this if possible.