==

==(other) Instance Public methods Equivalent to Array#==. Returns true if the two arrays contain the same number of elements and if each element is equal to the corresponding element in the other array, otherwise returns false. 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> # ] other = person.pets.to_ary person.pets == other # =

any?

any?(&block) Instance Public methods Returns true if the collection is not empty. class Person < ActiveRecord::Base has_many :pets end person.pets.count # => 0 person.pets.any? # => false person.pets << Pet.new(name: 'Snoop') person.pets.count # => 0 person.pets.any? # => true You can also pass a block to define criteria. The behavior is the same, it returns true if the collection based on the criteria is not empty. person.pets # => [#<Pet name

append

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

arel

arel() Instance Public methods

build

build(attributes = {}, &block) Instance Public methods Returns a new object of the collection type that has been instantiated with attributes and linked to this object, but have not yet been saved. You can pass an array of attributes hashes, this will return an array with the new objects. class Person has_many :pets end person.pets.build # => #<Pet id: nil, name: nil, person_id: 1> person.pets.build(name: 'Fancy-Fancy') # => #<Pet id: nil, name: "Fancy-Fancy"

clear

clear() Instance Public methods Equivalent to delete_all. The difference is that returns self, instead of an array with the deleted objects, so methods can be chained. See delete_all for more information.

concat

concat(*records) Instance Public methods Add one or more records to the collection by setting their foreign keys to the association's primary key. Since << flattens its argument list and inserts each record, push and concat behave identically. Returns self so method calls may be chained. class Person < ActiveRecord::Base has_many :pets end person.pets.size # => 0 person.pets.concat(Pet.new(name: 'Fancy-Fancy')) person.pets.concat(Pet.new(name: 'Spook'), Pet.new(name:

count

count(column_name = nil, options = {}) Instance Public methods Count all records using SQL. class Person < ActiveRecord::Base has_many :pets end person.pets.count # => 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-Choo", person_id: 1> # ]

create

create(attributes = {}, &block) Instance Public methods Returns a new object of the collection type that has been instantiated with attributes, linked to this object and that has already been saved (if it passes the validations). class Person has_many :pets end person.pets.create(name: 'Fancy-Fancy') # => #<Pet id: 1, name: "Fancy-Fancy", person_id: 1> person.pets.create([{name: 'Spook'}, {name: 'Choo-Choo'}]) # => [ # #<Pet id: 2, name: "Spook", person_

create!

create!(attributes = {}, &block) Instance Public methods Like create, except that if the record is invalid, raises an exception. class Person has_many :pets end class Pet validates :name, presence: true end person.pets.create!(name: nil) # => ActiveRecord::RecordInvalid: Validation failed: Name can't be blank