diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-01-26 03:18:21 -0800 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-02-02 10:19:23 -0200 |
commit | bf794bb36f3bd06e2e863cd6c6dfb6ceae116af2 (patch) | |
tree | a85eede4f3b73e3f05f3dbc113ae0b361f661867 /activerecord/lib/active_record | |
parent | 8f8ae5f03ccc30daae278c397fb88f94216b5229 (diff) | |
download | rails-bf794bb36f3bd06e2e863cd6c6dfb6ceae116af2.tar.gz rails-bf794bb36f3bd06e2e863cd6c6dfb6ceae116af2.tar.bz2 rails-bf794bb36f3bd06e2e863cd6c6dfb6ceae116af2.zip |
Merge pull request #9078 from senny/6865_ar_count_with_uniq
`#count` in conjunction with `#uniq` performs distinct count.
Conflicts:
activerecord/CHANGELOG.md
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 6e887f5203..1f9dbdc3d4 100644 --- a/activerecord/lib/active_record/relation/calculations.rb +++ b/activerecord/lib/active_record/relation/calculations.rb @@ -195,7 +195,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) |