diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2016-08-16 23:13:42 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2016-08-16 23:13:42 -0300 |
commit | 2af63c9c9f44028ca6c3a418756c1d0a783c12c5 (patch) | |
tree | f703e8734018e58eb49ffc092de978c55a88b509 /activerecord/lib | |
parent | af4dfa9e1ad85986f65f759f8222fc3bbbf1f4ef (diff) | |
parent | 0aae7806c10e3e3cce671c23dac6a8958ba89629 (diff) | |
download | rails-2af63c9c9f44028ca6c3a418756c1d0a783c12c5.tar.gz rails-2af63c9c9f44028ca6c3a418756c1d0a783c12c5.tar.bz2 rails-2af63c9c9f44028ca6c3a418756c1d0a783c12c5.zip |
Merge pull request #26121 from MaxLap/fix_count_with_left_joins
Fix count which would sometimes force a DISTINCT
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/relation/calculations.rb | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb index ecf3700aab..a4962879ab 100644 --- a/activerecord/lib/active_record/relation/calculations.rb +++ b/activerecord/lib/active_record/relation/calculations.rb @@ -117,7 +117,10 @@ module ActiveRecord end if has_include?(column_name) - construct_relation_for_association_calculations.calculate(operation, column_name) + relation = construct_relation_for_association_calculations + relation = relation.distinct if operation.to_s.downcase == "count" + + relation.calculate(operation, column_name) else perform_calculation(operation, column_name) end @@ -198,11 +201,6 @@ module ActiveRecord if operation == "count" column_name ||= select_for_count - - unless arel.ast.grep(Arel::Nodes::OuterJoin).empty? - distinct = true - end - column_name = primary_key if column_name == :all && distinct distinct = nil if column_name =~ /\s*DISTINCT[\s(]+/i end |