Distinct (ActiveRecord::Associations::CollectionProxy) - APIdock

method distinct v5.2.3 - Show latest stable - Class: ActiveRecord::Associations::CollectionProxy distinctpublic

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"> # ] Show source # File activerecord/lib/active_record/associations/collection_proxy.rb, line 723

Related methods

  • Instance methods
  • <<
  • ==
  • any?
  • append
  • build
  • calculate
  • clear
  • concat
  • count
  • create
  • create!
  • delete
  • delete_all
  • destroy
  • destroy_all
  • distinct
  • empty?
  • fifth
  • find
  • first
  • forty_two
  • fourth
  • include?
  • last
  • length
  • load_target
  • loaded?
  • many?
  • new
  • pluck
  • prepend
  • proxy_association
  • push
  • records
  • reload
  • replace
  • reset
  • reset_scope
  • scope
  • second
  • second_to_last
  • select
  • size
  • take
  • target
  • third
  • third_to_last
  • Class methods
  • new
  • Private methods
  • privateexec_queries
  • privatefind_from_target?
  • privatefind_nth_from_last
  • privatefind_nth_with_limit
  • privatenull_scope?

Tag » Activerecord Unique Associations