Module: Mongoid::Extensions::Hash::Assimilation

Included in:
Hash
Defined in:
lib/mongoid/extensions/hash/assimilation.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#assimilate(parent, options, type = nil) ⇒ Object

Introduces a child object into the Document object graph. This will set up the relationships between the parent and child and update the attributes of the parent Document.

Options:

parent: The Document to assimilate into. options: The association Options for the child.

Example:

{:first_name => "Hank", :last_name => "Moody"}.assimilate(name, options)

Returns: The child Document.



20
21
22
23
# File 'lib/mongoid/extensions/hash/assimilation.rb', line 20

def assimilate(parent, options, type = nil)
  child = type ? type.instantiate(self.merge(:_type => type.name)) : options.klass.instantiate(self)
  child.assimilate(parent, options)
end