aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/collection_proxy.rb
diff options
context:
space:
mode:
authorSean Griffin <sean@seantheprogrammer.com>2016-11-17 14:55:19 -0500
committerGitHub <noreply@github.com>2016-11-17 14:55:19 -0500
commit07af54d43cba30be7c206c5783ae15ab2cf37aa3 (patch)
tree920354ffda3eab692e5a9efb333b67f43cca492f /activerecord/lib/active_record/associations/collection_proxy.rb
parentf48bb1b4ad86bad71ae9c3e5dd3db6b4cb80e4d1 (diff)
parent0ec967aa6655d62c92f72acb8d556a5b3f70762d (diff)
downloadrails-07af54d43cba30be7c206c5783ae15ab2cf37aa3.tar.gz
rails-07af54d43cba30be7c206c5783ae15ab2cf37aa3.tar.bz2
rails-07af54d43cba30be7c206c5783ae15ab2cf37aa3.zip
Merge pull request #26980 from kamipo/respect_new_records_for_collection_proxy_distinct
Respect new records for `CollectionProxy#uniq`
Diffstat (limited to 'activerecord/lib/active_record/associations/collection_proxy.rb')
-rw-r--r--activerecord/lib/active_record/associations/collection_proxy.rb19
1 files changed, 16 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb
index 0800639c24..35a98d7090 100644
--- a/activerecord/lib/active_record/associations/collection_proxy.rb
+++ b/activerecord/lib/active_record/associations/collection_proxy.rb
@@ -718,6 +718,12 @@ module ActiveRecord
@association.destroy(*records)
end
+ ##
+ # :method: distinct
+ #
+ # :call-seq:
+ # distinct(value = true)
+ #
# Specifies whether the records should be unique or not.
#
# class Person < ActiveRecord::Base
@@ -732,10 +738,17 @@ module ActiveRecord
#
# person.pets.select(:name).distinct
# # => [#<Pet name: "Fancy-Fancy">]
- def distinct
- @association.distinct
+ #
+ # person.pets.select(:name).distinct.distinct(false)
+ # # => [
+ # # #<Pet name: "Fancy-Fancy">,
+ # # #<Pet name: "Fancy-Fancy">
+ # # ]
+
+ #--
+ def uniq
+ load_target.uniq
end
- alias uniq distinct
def calculate(operation, column_name)
null_scope? ? scope.calculate(operation, column_name) : super