Created
October 21, 2011 02:53
-
-
Save jswanner/1302999 to your computer and use it in GitHub Desktop.
Arel example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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