distinct

distinct()
Instance Public methods

Specifies whether the records should be unique or not.

1
2
3
4
5
6
7
8
9
10
11
12
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">]

uniq

doc_ruby_on_rails
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.