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
24
25
# File 'lib/mongoid/extensions/hash/assimilation.rb', line 20

def assimilate(parent, options, type = nil)
  klass = self.klass || (type ? type : options.klass)
  child = klass.instantiate("_id" => self["_id"])
  self.merge("_type" => klass.name) if klass.hereditary
  init(parent, child, options)
end