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

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

Overview

The Builder behavior for embedded_in associations.

Since:

  • 7.0

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 (Object)

    The object.

  • object (Object)

    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:

Since:

  • 7.0



29
30
31
32
33
34
35
36
# File 'build/mongoid-master/lib/mongoid/association/embedded/embedded_in/buildable.rb', line 29

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