Method: Mongoid::Association::Macros::ClassMethods#embedded_in

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

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

Adds the association back to the parent document. This macro is necessary to set the references from the child back to the parent document. If a child does not define this association calling persistence methods on the child object will cause a save to fail.

Examples:

Define the association.


class Person
  include Mongoid::Document
  embeds_many :addresses
end

class Address
  include Mongoid::Document
  embedded_in :person
end

Parameters:

  • name (Symbol)

    The name of the association.

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

    The association options.

  • &block

    Optional block for defining extensions.



80
81
82
# File 'lib/mongoid/association/macros.rb', line 80

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