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

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

Overview

:nodoc:

Instance Attribute Summary

Attributes inherited from Mongoid::Relations::Builder

#base, #metadata, #object

Instance Method Summary collapse

Methods included from Embedded::Sort

#sort_documents!

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.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/mongoid/relations/builders/embedded/many.rb', line 22

def build(type = nil)
  return [] if object.blank?
  return object if object.first.is_a?(Document)
  [].tap do |docs|
    object.each do |attrs|
      if _loading?
        docs << Factory.from_db(klass, attrs)
      else
        docs << Factory.build(klass, attrs)
      end
    end
    sort_documents!(docs, ) if .order
  end
end