Class: Mongoid::Relations::Builders::Referenced::Many

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

Overview

Since:

  • 2.0.0.rc.1

Instance Attribute Summary

Attributes inherited from Mongoid::Relations::Builder

#base, #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>

This builder either takes a hash and queries for the object or an array of documents, where it will just return tem.

Examples:

Build the documents.

Builder.new(meta, attrs).build

Parameters:

  • type (String) (defaults to: nil)

    The type of document to query for.

Returns:

Since:

  • 2.0.0.rc.1


17
18
19
20
21
22
# File 'lib/mongoid/relations/builders/referenced/many.rb', line 17

def build(type = nil)
  return object unless query?
  return [] if object.is_a?(Array)
  crit = .criteria(Conversions.flag(object, ), base.class)
  IdentityMap.get_many(crit.klass, crit.send(:selector_with_type_selection)) || crit
end