Rails: Order with nulls last -


in rails app i've run issue couple times i'd know how other people solve:

i have records value optional, records have value , null column.

if order column on databases nulls sort first , on databases nulls sort last.

for instance, have photos may or may not belong collection, ie there photos collection_id=nil , collection_id=1 etc.

if photo.order('collection_id desc) on sqlite nulls last on postgresql nulls first.

is there nice, standard rails way handle , consistent performance across database?

adding arrays preserve order:

@nonull = photo.where("collection_id not null").order("collection_id desc") @yesnull = photo.where("collection_id null") @wanted = @nonull+@yesnull 

http://www.ruby-doc.org/core/classes/array.html#m000271


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -