diff options
Diffstat (limited to 'lib/arel')
-rw-r--r-- | lib/arel/relations/operations/project.rb | 6 | ||||
-rw-r--r-- | lib/arel/sql/formatters.rb | 4 |
2 files changed, 5 insertions, 5 deletions
diff --git a/lib/arel/relations/operations/project.rb b/lib/arel/relations/operations/project.rb index d7835edda4..5507ea3163 100644 --- a/lib/arel/relations/operations/project.rb +++ b/lib/arel/relations/operations/project.rb @@ -2,7 +2,7 @@ module Arel class Project < Compound attributes :relation, :projections deriving :== - + def initialize(relation, *projections, &block) @relation = relation @projections = (projections + (block_given?? [yield(relation)] : [])).collect { |p| p.bind(relation) } @@ -11,9 +11,9 @@ module Arel def attributes @attributes ||= projections.collect { |p| p.bind(self) } end - + def externalizable? attributes.any?(&:aggregation?) or relation.externalizable? end end -end
\ No newline at end of file +end diff --git a/lib/arel/sql/formatters.rb b/lib/arel/sql/formatters.rb index aa10952d04..d8618ca2cc 100644 --- a/lib/arel/sql/formatters.rb +++ b/lib/arel/sql/formatters.rb @@ -25,7 +25,7 @@ module Arel if expression.function_sql == "DISTINCT" "#{expression.function_sql} #{expression.attribute.to_sql(self)}" + (expression.alias ? " AS #{quote_column_name(expression.alias)}" : '') else - "#{expression.function_sql}(#{expression.attribute.to_sql(self)})" + (expression.alias ? " AS #{quote_column_name(expression.alias)}" : '') + "#{expression.function_sql}(#{expression.attribute.to_sql(self)})" + (expression.alias ? " AS #{quote_column_name(expression.alias)}" : " AS #{expression.function_sql.to_s.downcase}_id") end end @@ -69,7 +69,7 @@ module Arel end def value(value) - value.to_sql(self) + quote value.to_sql(self) end def scalar(value, column = nil) |