aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/calculations.rb
diff options
context:
space:
mode:
authorEmilio Tagua <miloops@gmail.com>2009-06-02 11:40:01 -0300
committerEmilio Tagua <miloops@gmail.com>2009-06-02 11:40:01 -0300
commit522711952bf315bc52353e941183237a41f61b23 (patch)
treedebb3e1956a6e9b61fc0ff0df8b898d984c8cbf8 /activerecord/lib/active_record/calculations.rb
parentb3d40546923b194a89be0d9e00758864fa60b9e8 (diff)
downloadrails-522711952bf315bc52353e941183237a41f61b23.tar.gz
rails-522711952bf315bc52353e941183237a41f61b23.tar.bz2
rails-522711952bf315bc52353e941183237a41f61b23.zip
Refactors to work with latest Arel implementation.
Diffstat (limited to 'activerecord/lib/active_record/calculations.rb')
-rw-r--r--activerecord/lib/active_record/calculations.rb19
1 files changed, 9 insertions, 10 deletions
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