Module: Mongoid::Association::Embedded::EmbeddedIn::Buildable

Includes:
Threaded::Lifecycle
Included in:
Mongoid::Association::Embedded::EmbeddedIn
Defined in:
lib/mongoid/association/embedded/embedded_in/buildable.rb

Overview

The Builder behavior for embedded_in associations.

Instance Method Summary collapse

Instance Method Details

#build(base, object, type = nil, selected_fields = nil) ⇒ Document

This builder doesn’t actually build anything, just returns the parent since it should already be instantiated.

Examples:

Build the document.

Builder.new(meta, attrs).build

Parameters:

  • base (Document)

    The object.

  • object (Document | Hash)

    The parent hash or document.

  • type (String) (defaults to: nil)

    Not used in this context.

  • selected_fields (Hash) (defaults to: nil)

    Fields which were retrieved via #only. If selected_fields are specified, fields not listed in it will not be accessible in the built document.

Returns:



27
28
29
30
31
32
33
34
# File 'lib/mongoid/association/embedded/embedded_in/buildable.rb', line 27

def build(base, object, type = nil, selected_fields = nil)
  return object unless object.is_a?(Hash)
  if _loading?
    Factory.from_db(klass, object, nil, selected_fields)
  else
    Factory.build(klass, object)
  end
end