module Mongoid::Association::Embedded::EmbeddedIn::Buildable

The Builder behavior for embedded_in associations.

@since 7.0

Public Instance Methods

build(base, object, type = nil, selected_fields = nil) click to toggle source

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

@example Build the document.

Builder.new(meta, attrs).build

@param [ Object ] base The object. @param [ Object ] object The parent hash or document. @param [ String ] type Not used in this context. @param [ Hash ] selected_fields Fields which were retrieved via

#only. If selected_fields are specified, fields not listed in it
will not be accessible in the built document.

@return [ Document ] A single document.

# File 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