From 522711952bf315bc52353e941183237a41f61b23 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 2 Jun 2009 11:40:01 -0300 Subject: Refactors to work with latest Arel implementation. --- activerecord/lib/active_record/calculations.rb | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'activerecord/lib/active_record/calculations.rb') diff --git a/activerecord/lib/active_record/calculations.rb b/activerecord/lib/active_record/calculations.rb index 98f9450662..8b8fb37d2d 100644 --- a/activerecord/lib/active_record/calculations.rb +++ b/activerecord/lib/active_record/calculations.rb @@ -161,19 +161,18 @@ module ActiveRecord end def execute_simple_calculation(operation, column_name, options) #:nodoc: - table = options[:from] || table_name - - value = if operation == 'count' - if column_name == :all && options[:select].blank? - column_name = "*" - elsif !options[:select].blank? - column_name = options[:select] - end - construct_calculation_arel(options.merge(:select => Arel::Attribute.new(Arel(table), column_name).count(options[:distinct]))) + column = if column_names.include?(column_name.to_s) + Arel::Attribute.new(arel_table(options[:from] || table_name), + options[:select] || column_name) else - construct_calculation_arel(options.merge(:select => Arel::Attribute.new(Arel(table), column_name).send(operation))) + Arel::SqlLiteral.new(options[:select] || + (column_name == :all ? "*" : column_name.to_s)) end + value = construct_calculation_arel(options.merge( + :select => operation == 'count' ? column.count(options[:distinct]) : column.send(operation) + )) + type_cast_calculated_value(connection.select_value(value.to_sql), column_for(column_name), operation) end -- cgit v1.2.3