diff options
author | Jon Leighton <j@jonathanleighton.com> | 2013-03-15 06:21:53 -0700 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2013-03-15 06:21:53 -0700 |
commit | 0721d3b37062eca73da3efd669142d7e381e4d80 (patch) | |
tree | 75a10eb4357b101161563c380e676412dcc4c455 /guides | |
parent | df21d1eaee11e82c9a83566e2d7c4b771e344686 (diff) | |
parent | cd87c85ef05e47f6ea1ce7422ae033fe6d82b030 (diff) | |
download | rails-0721d3b37062eca73da3efd669142d7e381e4d80.tar.gz rails-0721d3b37062eca73da3efd669142d7e381e4d80.tar.bz2 rails-0721d3b37062eca73da3efd669142d7e381e4d80.zip |
Merge pull request #9683 from senny/deprecate_count_distinct_option
rename `Relation#uniq` to `Relation#distinct`
Diffstat (limited to 'guides')
-rw-r--r-- | guides/source/active_record_querying.md | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/guides/source/active_record_querying.md b/guides/source/active_record_querying.md index 4a4f814917..7355f6816c 100644 --- a/guides/source/active_record_querying.md +++ b/guides/source/active_record_querying.md @@ -76,6 +76,7 @@ The methods are: * `reorder` * `reverse_order` * `select` +* `distinct` * `uniq` * `where` @@ -580,10 +581,10 @@ ActiveModel::MissingAttributeError: missing attribute: <attribute> Where `<attribute>` is the attribute you asked for. The `id` method will not raise the `ActiveRecord::MissingAttributeError`, so just be careful when working with associations because they need the `id` method to function properly. -If you would like to only grab a single record per unique value in a certain field, you can use `uniq`: +If you would like to only grab a single record per unique value in a certain field, you can use `distinct`: ```ruby -Client.select(:name).uniq +Client.select(:name).distinct ``` This would generate SQL like: @@ -595,10 +596,10 @@ SELECT DISTINCT name FROM clients You can also remove the uniqueness constraint: ```ruby -query = Client.select(:name).uniq +query = Client.select(:name).distinct # => Returns unique names -query.uniq(false) +query.distinct(false) # => Returns all names, even if there are duplicates ``` @@ -1438,7 +1439,7 @@ Client.where(active: true).pluck(:id) # SELECT id FROM clients WHERE active = 1 # => [1, 2, 3] -Client.uniq.pluck(:role) +Client.distinct.pluck(:role) # SELECT DISTINCT role FROM clients # => ['admin', 'member', 'guest'] |