module Mongoid::Association::Embedded::EmbedsMany::Buildable

def build(base, object, type = nil, selected_fields = nil)

Returns:
  • (Array - Array

Parameters:

  • selected_fields (Hash) -- Fields which were retrieved via
  • type (String) -- Not used in this context.
  • object (Object) -- The object to use to build the association.
  • base (Object) -- The base object.

Other tags:
    Example: Build the documents. -
def build(base, object, type = nil, selected_fields = nil)
  return [] if object.blank?
  return object if object.first.is_a?(Document)
  docs = []
  object.each do |attrs|
    if _loading? && base.persisted?
      docs.push(Factory.from_db(klass, attrs, nil, selected_fields))
    else
      docs.push(Factory.build(klass, attrs))
    end
  end
  docs
end