diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-05-11 13:32:04 -0700 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2011-05-11 13:32:04 -0700 |
commit | d192d85668e967547a20cdbd0a0f40a8477b272a (patch) | |
tree | 828c20fca51384584b917704d0aad0781bf30888 /activerecord/lib | |
parent | c53d3929cd5d7a2ac39411c8137d469e5047a4f4 (diff) | |
parent | 1db49ced45819c7284dfd63aad791ead3a26203e (diff) | |
download | rails-d192d85668e967547a20cdbd0a0f40a8477b272a.tar.gz rails-d192d85668e967547a20cdbd0a0f40a8477b272a.tar.bz2 rails-d192d85668e967547a20cdbd0a0f40a8477b272a.zip |
Merge pull request #512 from pivotalneutron/fix_eager_load_with_calculations
Bug fixes for calculations with includes
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/relation/calculations.rb | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb index a8a52867ce..0fcae92d51 100644 --- a/activerecord/lib/active_record/relation/calculations.rb +++ b/activerecord/lib/active_record/relation/calculations.rb @@ -146,7 +146,7 @@ module ActiveRecord if options.except(:distinct).present? apply_finder_options(options.except(:distinct)).calculate(operation, column_name, :distinct => options[:distinct]) else - if eager_loading? || includes_values.present? + if eager_loading? || (includes_values.present? && references_eager_loaded_tables?) construct_relation_for_association_calculations.calculate(operation, column_name, options) else perform_calculation(operation, column_name, options) @@ -161,21 +161,20 @@ module ActiveRecord def perform_calculation(operation, column_name, options = {}) operation = operation.to_s.downcase - distinct = nil + distinct = options[:distinct] if operation == "count" column_name ||= (select_for_count || :all) unless arel.ast.grep(Arel::Nodes::OuterJoin).empty? distinct = true - column_name = primary_key if column_name == :all end + column_name = primary_key if column_name == :all && distinct + distinct = nil if column_name =~ /\s*DISTINCT\s+/i end - distinct = options[:distinct] || distinct - if @group_values.any? execute_grouped_calculation(operation, column_name, distinct) else |