diff options
author | Yves Senn <yves.senn@oxon.ch> | 2013-01-23 16:28:17 +0100 |
---|---|---|
committer | Yves Senn <yves.senn@oxon.ch> | 2013-01-26 12:16:28 +0100 |
commit | 648def406023b38310287588eb5efdfc739253e2 (patch) | |
tree | 120f7451a424cb8478ed14f64389bdb49ce5accf /activerecord/lib/active_record | |
parent | 01341e3e432f0602891fe226ed1f2d079f590327 (diff) | |
download | rails-648def406023b38310287588eb5efdfc739253e2.tar.gz rails-648def406023b38310287588eb5efdfc739253e2.tar.bz2 rails-648def406023b38310287588eb5efdfc739253e2.zip |
`#count` in conjunction with `#uniq` performs distinct count.
closes #6865
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/relation/calculations.rb | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb index 3f154bd1cc..f10c290755 100644 --- a/activerecord/lib/active_record/relation/calculations.rb +++ b/activerecord/lib/active_record/relation/calculations.rb @@ -192,7 +192,8 @@ module ActiveRecord def perform_calculation(operation, column_name, options = {}) operation = operation.to_s.downcase - distinct = options[:distinct] + # If #count is used in conjuction with #uniq it is considered distinct. (eg. relation.uniq.count) + distinct = options[:distinct] || self.uniq_value if operation == "count" column_name ||= (select_for_count || :all) |