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.

Since:

  • 7.0

Instance Method Summary collapse

Instance Method Details

#build(base, object, type = 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.

Returns:

Since:

  • 7.0



23
24
25
26
27
28
29
30
# File 'lib/mongoid/association/embedded/embedded_in/buildable.rb', line 23

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