diff options
author | Fadzril Muhamad & Joseph Palermo <pair+fadzril+jpalermo@pivotallabs.com> | 2011-05-11 17:19:06 +0800 |
---|---|---|
committer | Joseph Palermo <pair+jpalermo@pivotallabs.com> | 2011-05-12 04:05:24 +0800 |
commit | 1db49ced45819c7284dfd63aad791ead3a26203e (patch) | |
tree | 878f17aa7ac3fbc1fc9c068ea43ce4d2e6ebc98a /activerecord/lib | |
parent | 1dd90f8f12d1904ee3db37f9390df3246bb2712b (diff) | |
download | rails-1db49ced45819c7284dfd63aad791ead3a26203e.tar.gz rails-1db49ced45819c7284dfd63aad791ead3a26203e.tar.bz2 rails-1db49ced45819c7284dfd63aad791ead3a26203e.zip |
Bug fixes:
- If doing a count on a relation that has an :include and a :join, it does a distinct even though it should not.
- When doing a count on a relation that has an :include, it always falls back to a old style left join when performing the count. Looks like it was broken here:
https://github.com/rails/rails/commit/b9599502c9e738a5a1513e75d08f8d40ed408265
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 |