include?

include?(record) Instance Public methods Returns true if the given object is present in the collection. class Person < ActiveRecord::Base has_many :pets end person.pets # => [#<Pet id: 20, name: "Snoop">] person.pets.include?(Pet.find(20)) # => true person.pets.include?(Pet.find(21)) # => false

fourth

fourth(*args) Instance Public methods Same as first except returns only the fourth record.

forty_two

forty_two(*args) Instance Public methods Same as first except returns only the forty second record. Also known as accessing âthe redditâ.

first

first(*args) Instance Public methods Returns the first record, or the first n records, from the collection. If the collection is empty, the first form returns nil, and the second form returns an empty array. class Person < ActiveRecord::Base has_many :pets end person.pets # => [ # #<Pet id: 1, name: "Fancy-Fancy", person_id: 1>, # #<Pet id: 2, name: "Spook", person_id: 1>, # #<Pet id: 3, name: "Choo-Choo", person_id: 1> # ] person.pe

find

find(*args, &block) Instance Public methods Finds an object in the collection responding to the id. Uses the same rules as ActiveRecord::Base.find. Returns ActiveRecord::RecordNotFound error if the object cannot be found. class Person < ActiveRecord::Base has_many :pets end person.pets # => [ # #<Pet id: 1, name: "Fancy-Fancy", person_id: 1>, # #<Pet id: 2, name: "Spook", person_id: 1>, # #<Pet id: 3, name: "Choo-Choo", person_id: 1>

fifth

fifth(*args) Instance Public methods Same as first except returns only the fifth record.

empty?

empty?() Instance Public methods Returns true if the collection is empty. If the collection has been loaded it is equivalent to collection.size.zero?. If the collection has not been loaded, it is equivalent to collection.exists?. If the collection has not already been loaded and you are going to fetch the records anyway it is better to check collection.length.zero?. class Person < ActiveRecord::Base has_many :pets end person.pets.count # => 1 person.pets.empty? # => fa

distinct

distinct() Instance Public methods 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">] uniq

destroy_all

destroy_all() Instance Public methods Deletes the records of the collection directly from the database ignoring the :dependent option. It invokes before_remove, after_remove , before_destroy and after_destroy callbacks. class Person < ActiveRecord::Base has_many :pets end person.pets.size # => 3 person.pets # => [ # #<Pet id: 1, name: "Fancy-Fancy", person_id: 1>, # #<Pet id: 2, name: "Spook", person_id: 1>, # #<Pet id: 3, name: "Choo-Ch

destroy

destroy(*records) Instance Public methods Destroys the records supplied and removes them from the collection. This method will always remove record from the database ignoring the :dependent option. Returns an array with the removed records. class Person < ActiveRecord::Base has_many :pets end person.pets.size # => 3 person.pets # => [ # #<Pet id: 1, name: "Fancy-Fancy", person_id: 1>, # #<Pet id: 2, name: "Spook", person_id: 1>, # #<Pet