aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorEmilio Tagua <miloops@gmail.com>2009-06-23 19:40:57 -0300
committerEmilio Tagua <miloops@gmail.com>2009-06-23 19:40:57 -0300
commit3b27a4856f9a1a4d8f4e6d80343fcd5a80c40b35 (patch)
tree4787463dd64854ad9d305968a715ec80a183c2f7 /activerecord
parentb9088dce07f8525cdb84a1312a77b81db79067d6 (diff)
downloadrails-3b27a4856f9a1a4d8f4e6d80343fcd5a80c40b35.tar.gz
rails-3b27a4856f9a1a4d8f4e6d80343fcd5a80c40b35.tar.bz2
rails-3b27a4856f9a1a4d8f4e6d80343fcd5a80c40b35.zip
Refactoring: Calculations now use construct_finder_sql instead they own method.
Diffstat (limited to 'activerecord')
-rwxr-xr-xactiverecord/lib/active_record/base.rb10
-rw-r--r--activerecord/lib/active_record/calculations.rb23
2 files changed, 8 insertions, 25 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 2453d38aca..c7fc1fa124 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -1696,11 +1696,9 @@ module ActiveRecord #:nodoc:
@arel_table = Arel::Table.new(table)
end
- def construct_finder_arel(options)
- scope = scope(:find)
-
+ def construct_finder_arel(options, scope = scope(:find))
# TODO add lock to Arel
- arel_table(table_name).
+ arel_table(options[:from] || table_name).
join(construct_join(options[:joins], scope)).
where(construct_conditions(options[:conditions], scope)).
project(options[:select] || (scope && scope[:select]) || default_select(options[:joins] || (scope && scope[:joins]))).
@@ -1711,8 +1709,8 @@ module ActiveRecord #:nodoc:
)
end
- def construct_finder_sql(options)
- construct_finder_arel(options).to_sql
+ def construct_finder_sql(options, scope = scope(:find))
+ construct_finder_arel(options, scope).to_sql
end
def construct_join(joins, scope)
diff --git a/activerecord/lib/active_record/calculations.rb b/activerecord/lib/active_record/calculations.rb
index 15ca5e14a2..5c7247b9c0 100644
--- a/activerecord/lib/active_record/calculations.rb
+++ b/activerecord/lib/active_record/calculations.rb
@@ -169,11 +169,11 @@ module ActiveRecord
(column_name == :all ? "*" : column_name.to_s))
end
- value = construct_calculation_arel(options.merge(
+ value = construct_finder_sql(options.merge(
:select => operation == 'count' ? column.count(options[:distinct]) : column.send(operation)
- ))
+ ), nil)
- type_cast_calculated_value(connection.select_value(value.to_sql), column_for(column_name), operation)
+ type_cast_calculated_value(connection.select_value(value), column_for(column_name), operation)
end
def execute_grouped_calculation(operation, column_name, options) #:nodoc:
@@ -194,7 +194,7 @@ module ActiveRecord
options[:select] << ", #{group_field} AS #{group_alias}"
- calculated_data = connection.select_all(construct_calculation_arel(options).to_sql)
+ calculated_data = connection.select_all(construct_finder_sql(options, nil))
if association
key_ids = calculated_data.collect { |row| row[group_alias] }
@@ -212,21 +212,6 @@ module ActiveRecord
end
protected
-
- def construct_calculation_arel(options)
- scope = scope(:find)
-
- arel_table(options[:from] || table_name).
- join(options[:joins]).
- where(options[:conditions]).
- project(options[:select]).
- group(construct_group(options[:group], options[:having], scope)).
- order(options[:order].to_s).
- take(construct_limit(options, scope)).
- skip(construct_offset(options, scope)
- )
- end
-
def construct_count_options_from_args(*args)
options = {}
column_name = :all