diff options
author | Emilio Tagua <miloops@gmail.com> | 2009-08-14 12:33:05 -0300 |
---|---|---|
committer | Emilio Tagua <miloops@gmail.com> | 2009-08-14 12:33:05 -0300 |
commit | 9ac01fad193b27e517ea772e0d1e13e06f4ddf34 (patch) | |
tree | 87182ceef9887c04ce77c37decdbea408c1e1ebb /activerecord/lib/active_record/calculations.rb | |
parent | b68ef73344003949e302d784ff3cca6a95192ce0 (diff) | |
download | rails-9ac01fad193b27e517ea772e0d1e13e06f4ddf34.tar.gz rails-9ac01fad193b27e517ea772e0d1e13e06f4ddf34.tar.bz2 rails-9ac01fad193b27e517ea772e0d1e13e06f4ddf34.zip |
Use ARel's joins when building a query for finding records with included
associations.
Diffstat (limited to 'activerecord/lib/active_record/calculations.rb')
-rw-r--r-- | activerecord/lib/active_record/calculations.rb | 23 |
1 files changed, 6 insertions, 17 deletions
diff --git a/activerecord/lib/active_record/calculations.rb b/activerecord/lib/active_record/calculations.rb index 6a5f2222a2..ab501dac33 100644 --- a/activerecord/lib/active_record/calculations.rb +++ b/activerecord/lib/active_record/calculations.rb @@ -128,12 +128,6 @@ module ActiveRecord scope = scope(:find) merged_includes = merge_includes(scope ? scope[:include] : [], options[:include]) - joins = construct_join(options[:joins], scope) - - if merged_includes.any? - join_dependency = ActiveRecord::Associations::ClassMethods::JoinDependency.new(self, merged_includes, joins) - joins << join_dependency.join_associations.collect{|join| join.association_join }.join - end if operation == "count" if merged_includes.any? @@ -148,17 +142,12 @@ module ActiveRecord end catch :invalid_query do - relation = arel_table((scope && scope[:from]) || options[:from]) - - relation.join(joins) - - relation.where(construct_conditions(options[:conditions], scope)) - relation.where(construct_arel_limited_ids_condition(options, join_dependency)) if join_dependency && !using_limitable_reflections?(join_dependency.reflections) && ((scope && scope[:limit]) || options[:limit]) - - relation.order(options[:order]) - relation.take(options[:limit]) - relation.skip(options[:offset]) - + relation = if merged_includes.any? + join_dependency = ActiveRecord::Associations::ClassMethods::JoinDependency.new(self, merged_includes, construct_join(options[:joins], scope)) + construct_finder_arel_with_included_associations(options, join_dependency) + else + construct_finder_arel(options) + end if options[:group] return execute_grouped_calculation(operation, column_name, options, relation) else |