reload

reload() Instance Public methods Reloads the collection from the database. Returns self. Equivalent to collection(true). class Person < ActiveRecord::Base has_many :pets end person.pets # fetches pets from the database # => [#<Pet id: 1, name: "Snoop", group: "dogs", person_id: 1>] person.pets # uses the pets cache # => [#<Pet id: 1, name: "Snoop", group: "dogs", person_id: 1>] person.pets.reload # fetches pets from the database # => [#<Pet id: 1, na

push

push(*records) Instance Public methods Alias for: <<

proxy_association

proxy_association() Instance Public methods

prepend

prepend(*args) Instance Public methods

new

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

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

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

load_target

load_target() Instance Public methods

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

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.