diff options
author | Yves Senn <yves.senn@gmail.com> | 2013-03-12 10:52:25 +0100 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2013-03-15 14:15:47 +0100 |
commit | cd87c85ef05e47f6ea1ce7422ae033fe6d82b030 (patch) | |
tree | d4a74669f3f5a9dd8900b688e4e00481c0a8b1e9 /activerecord/lib/active_record/relation | |
parent | a1bb6c8b06db83546179175b9b2dde7912c86f9b (diff) | |
download | rails-cd87c85ef05e47f6ea1ce7422ae033fe6d82b030.tar.gz rails-cd87c85ef05e47f6ea1ce7422ae033fe6d82b030.tar.bz2 rails-cd87c85ef05e47f6ea1ce7422ae033fe6d82b030.zip |
Deprecate the `:distinct` option for `Relation#count`.
We moved more and more away from passing options to finder / calculation
methods. The `:distinct` option in `#count` was one of the remaining places.
Since we can now combine `Relation#distinct` with `Relation#count` the option
is no longer necessary and can be deprecated.
Diffstat (limited to 'activerecord/lib/active_record/relation')
-rw-r--r-- | activerecord/lib/active_record/relation/calculations.rb | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb index 6fedfefdee..be011b22af 100644 --- a/activerecord/lib/active_record/relation/calculations.rb +++ b/activerecord/lib/active_record/relation/calculations.rb @@ -11,7 +11,7 @@ module ActiveRecord # Person.count(:all) # # => performs a COUNT(*) (:all is an alias for '*') # - # Person.count(:age, distinct: true) + # Person.distinct.count(:age) # # => counts the number of different age values # # If +count+ is used with +group+, it returns a Hash whose keys represent the aggregated column, @@ -199,7 +199,12 @@ module ActiveRecord operation = operation.to_s.downcase # If #count is used with #distinct / #uniq it is considered distinct. (eg. relation.distinct.count) - distinct = options[:distinct] || self.distinct_value + distinct = self.distinct_value + if options.has_key?(:distinct) + ActiveSupport::Deprecation.warn "The :distinct option for `Relation#count` is deprecated. " \ + "Please use `Relation#distinct` instead. (eg. `relation.distinct.count`)" + distinct = options[:distinct] + end if operation == "count" column_name ||= (select_for_count || :all) |