Class: Mongoid::Relations::Builders::Embedded::Many

Inherits:
Mongoid::Relations::Builder show all
Defined in:
lib/mongoid/relations/builders/embedded/many.rb

Overview

:nodoc:

Instance Attribute Summary

Attributes inherited from Mongoid::Relations::Builder

#metadata, #object

Instance Method Summary collapse

Methods inherited from Mongoid::Relations::Builder

#initialize

Constructor Details

This class inherits a constructor from Mongoid::Relations::Builder

Instance Method Details

#build(type = nil) ⇒ Array<Document ] The documents.

Builds the document out of the attributes using the provided metadata on the relation. Instantiates through the factory in order to make sure subclasses and allocation are used if fitting. This case will return many documents.

Examples:

Build the documents.

Builder.new(meta, attrs).build

Parameters:

  • type (String) (defaults to: nil)

    Not used in this context.

Returns:

  • (Array<Document ] The documents.)

    Array<Document ] The documents.



19
20
21
22
23
24
25
26
27
# File 'lib/mongoid/relations/builders/embedded/many.rb', line 19

def build(type = nil)
  return [] if object.blank?
  return object if object.first.is_a?(Document)
  object.inject([]) do |documents, attrs|
    documents.tap do |docs|
      docs << Mongoid::Factory.from_db(.klass, attrs)
    end
  end
end