aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation/query_methods.rb
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2013-03-12 10:23:08 +0100
committerYves Senn <yves.senn@gmail.com>2013-03-15 14:15:47 +0100
commita1bb6c8b06db83546179175b9b2dde7912c86f9b (patch)
tree136a3a72f5e612b847e953b2ea12bacd53336040 /activerecord/lib/active_record/relation/query_methods.rb
parentbfee706b2e8c3f0144588fb034d41c8333bcd88e (diff)
downloadrails-a1bb6c8b06db83546179175b9b2dde7912c86f9b.tar.gz
rails-a1bb6c8b06db83546179175b9b2dde7912c86f9b.tar.bz2
rails-a1bb6c8b06db83546179175b9b2dde7912c86f9b.zip
rename `Relation#uniq` to `Relation#distinct`. `#uniq` still works.
The similarity of `Relation#uniq` to `Array#uniq` is confusing. Since our Relation API is close to SQL terms I renamed `#uniq` to `#distinct`. There is no deprecation. `#uniq` and `#uniq!` are aliases and will continue to work. I also updated the documentation to promote the use of `#distinct`.
Diffstat (limited to 'activerecord/lib/active_record/relation/query_methods.rb')
-rw-r--r--activerecord/lib/active_record/relation/query_methods.rb20
1 files changed, 11 insertions, 9 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb
index b7960936cf..10a31109d5 100644
--- a/activerecord/lib/active_record/relation/query_methods.rb
+++ b/activerecord/lib/active_record/relation/query_methods.rb
@@ -710,20 +710,22 @@ module ActiveRecord
# User.select(:name)
# # => Might return two records with the same name
#
- # User.select(:name).uniq
- # # => Returns 1 record per unique name
+ # User.select(:name).distinct
+ # # => Returns 1 record per distinct name
#
- # User.select(:name).uniq.uniq(false)
+ # User.select(:name).distinct.distinct(false)
# # => You can also remove the uniqueness
- def uniq(value = true)
- spawn.uniq!(value)
+ def distinct(value = true)
+ spawn.distinct!(value)
end
+ alias uniq distinct
- # Like #uniq, but modifies relation in place.
- def uniq!(value = true) # :nodoc:
- self.uniq_value = value
+ # Like #distinct, but modifies relation in place.
+ def distinct!(value = true) # :nodoc:
+ self.distinct_value = value
self
end
+ alias uniq! distinct!
# Used to extend a scope with additional methods, either through
# a module or through a block provided.
@@ -814,7 +816,7 @@ module ActiveRecord
build_select(arel, select_values.uniq)
- arel.distinct(uniq_value)
+ arel.distinct(distinct_value)
arel.from(build_from) if from_value
arel.lock(lock_value) if lock_value