Method: Mongoid::Association::Macros::ClassMethods#has_many

Defined in:
lib/mongoid/association/macros.rb

#has_many(name, options = {}, &block) ⇒ Object

Adds a referenced association from a parent Document to many Documents in another database or collection.

Examples:

Define the association.


class Person
  include Mongoid::Document
  has_many :posts
end

class Game
  include Mongoid::Document
  belongs_to :person
end

Parameters:

  • name (Symbol)

    The name of the association.

  • options (Hash) (defaults to: {})

    The association options.

  • &block

    Optional block for defining extensions.



172
173
174
# File 'lib/mongoid/association/macros.rb', line 172

def has_many(name, options = {}, &block)
  define_association!(__method__, name, options, &block)
end