lib/mongoid/association/macros.rb
# 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.
#
# @example Define the association.
#
#   class Person
#     include Mongoid::Document
#     embeds_many :addresses
#   end
#
#   class Address
#     include Mongoid::Document
#     embedded_in :person
#   end
#
# @param [ Symbol ] name The name of the association.
# @param [ Hash ] options The association options.
# @param [ Proc ] block Optional block for defining extensions.
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.
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 .
def define_association!(macro_name, name, options = {}, &block)
          Association::MACRO_MAPPING[macro_name].new(self, name, options, &block).tap do |assoc|
            assoc.setup!
            self.relations = self.relations.merge(name => assoc)
            if assoc.embedded? && assoc.respond_to?(:store_as) && assoc.store_as != name
              self.aliased_associations[assoc.store_as] = name
            end
          end
        end
def define_association! ( macro_name , name , options = { } , & block ) Association :: MACRO_MAPPING [ macro_name ] . new ( self , name , options , & block ) . tap do | assoc | assoc . setup! self . relations = self . relations . merge ( name => assoc ) if assoc . embedded? && assoc . respond_to? ( :store_as ) && assoc . store_as != name self . aliased_associations [ assoc . store_as ] = name end end end
Adds the association back to the parent document.
Adds the association back to the parent document .
macro_name
<not_specific>
name
<not_specific>
options
<not_specific>
block
<not_specific>
<not_specific>
block Optional block for defining extensions.
block Optional block for defining extensions .
example
Define the association. class Person include Mongoid::Document embeds_many :addresses end class Address include Mongoid::Document embedded_in :person end
Define the association . class Person include Mongoid :: Document embeds_many : addresses end class Address include Mongoid :: Document embedded_in : person end