activerecord - Is there a more database agnostic way to write this default scope in Rails 3? -


i have following default scope defined in 1 of models

default_scope order("if(format = #{formats[:wide]}, 1, 0) desc, created_at desc, name asc") 

it worked fine on dev machine i'm running mysql, borked when deployed production use postgres. there way write using arel instead of straight sql? formats[:wide] returns integer, may not in particular order. want records particular format returned first.

i wouldn't put in sql @ all. make scope each format type , use ruby determine use. or create method determines sort order , passes wherever using it.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -