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

==

==(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 # =

&lt;&lt;

<<(*records) Instance Public methods Adds one or more records to the collection by setting their foreign keys to the association's primary key. Returns self, so several appends may be chained together. class Person < ActiveRecord::Base has_many :pets end person.pets.size # => 0 person.pets << Pet.new(name: 'Fancy-Fancy') person.pets << [Pet.new(name: 'Spook'), Pet.new(name: 'Choo-Choo')] person.pets.size # => 3 person.id # => 1 person.pets # =>

has_one

has_one(name, scope = nil, options = {}) Instance Public methods Specifies a one-to-one association with another class. This method should only be used if the other class contains the foreign key. If the current class contains the foreign key, then you should use belongs_to instead. See also ActiveRecord::Associations::ClassMethods's overview on when to use has_one and when to use belongs_to. The following methods for retrieval and query of a single associated object will be added:

has_many

has_many(name, scope = nil, options = {}, &extension) Instance Public methods Specifies a one-to-many association. The following methods for retrieval and query of collections of associated objects will be added: collection(force_reload = false) Returns an array of all the associated objects. An empty array is returned if none are found. collection<<(object, â¦) Adds one or more objects to the collection by setting their foreign keys to the collection's primary key.

has_and_belongs_to_many

has_and_belongs_to_many(name, scope = nil, options = {}, &extension) Instance Public methods Specifies a many-to-many relationship with another class. This associates two classes via an intermediate join table. Unless the join table is explicitly specified as an option, it is guessed using the lexical order of the class names. So a join between Developer and Project will give the default join table name of âdevelopers_projectsâ because âDâ precedes âPâ alphabetically. Note that

belongs_to

belongs_to(name, scope = nil, options = {}) Instance Public methods Specifies a one-to-one association with another class. This method should only be used if this class contains the foreign key. If the other class contains the foreign key, then you should use has_one instead. See also ActiveRecord::Associations::ClassMethods's overview on when to use has_one and when to use belongs_to. Methods will be added for retrieval and query for a single associated object, for which this obje

build

build(lhs_class, name, options) Class Public methods

join_table

join_table() Instance Public methods

new

new(lhs_class, rhs_class_name) Class Public methods