Skip to content

Instantly share code, notes, and snippets.

@jswanner
Created October 21, 2011 02:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jswanner/1302999 to your computer and use it in GitHub Desktop.
Save jswanner/1302999 to your computer and use it in GitHub Desktop.
Arel example
# before
def self.front_page
where(:front_page => true).select('*, coalesce(position, 999999999) AS position').order('position ASC')
end
# after
def self.front_page
where(:front_page => true).select([
Arel.sql('*'),
Arel::Nodes::NamedFunction.new('COALESCE', [arel_table[:position], 999999999]).as('position')
]).order('position ASC')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment