fourth

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

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

last

last(*args) Instance Public methods Returns the last record, or the last 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.pets.

length

length() Instance Public methods Returns the size of the collection calling size on the target. If the collection has been already loaded, length and size are equivalent. If not and you are going to need the records anyway this method will take one less query. Otherwise size is more efficient. class Person < ActiveRecord::Base has_many :pets end person.pets.length # => 3 # executes something like SELECT "pets".* FROM "pets" WHERE "pets"."person_id" = 1 # Because the colle

load_target

load_target() Instance Public methods

loaded?

loaded?() Instance Public methods Returns true if the association has been loaded, otherwise false. person.pets.loaded? # => false person.pets person.pets.loaded? # => true

many?

many?(&block) Instance Public methods Returns true if the collection has more than one record. Equivalent to collection.size > 1. class Person < ActiveRecord::Base has_many :pets end person.pets.count # => 1 person.pets.many? # => false person.pets << Pet.new(name: 'Snoopy') person.pets.count # => 2 person.pets.many? # => true You can also pass a block to define criteria. The behavior is the same, it returns true if the collection based on the crite

new

new(attributes = {}, &block) Instance Public methods Alias for: build

prepend

prepend(*args) Instance Public methods

proxy_association

proxy_association() Instance Public methods