module Mongoid::Association::Referenced::HasAndBelongsToMany::Buildable

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

Returns:
  • (Array) - The documents.

Parameters:
  • selected_fields (nil) -- Must be nil.
  • 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)
  if query?(object)
    query_criteria(object)
  else
    object.try(:dup)
  end
end

def query?(object)

def query?(object)
  object.nil? || Array(object).all? { |d| !d.is_a?(Mongoid::Document) }
end