instance method
distinct
Ruby on Rails 7.0.10
Since v4.0.13Signature
distinct(value = true)
Specifies whether the records should be unique or not.
class Person < ActiveRecord::Base
has_many :pets
end
person.pets.select(:name)
# => [
# #<Pet name: "Fancy-Fancy">,
# #<Pet name: "Fancy-Fancy">
# ]
person.pets.select(:name).distinct
# => [#<Pet name: "Fancy-Fancy">]
person.pets.select(:name).distinct.distinct(false)
# => [
# #<Pet name: "Fancy-Fancy">,
# #<Pet name: "Fancy-Fancy">
# ]
Source
# File activerecord/lib/active_record/associations/collection_proxy.rb, line 695
Defined in activerecord/lib/active_record/associations/collection_proxy.rb line 695
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::Associations::CollectionProxy