Class: Mongoid::Relations::Builders::Referenced::In

Inherits:
Mongoid::Relations::Builder show all
Defined in:
lib/mongoid/relations/builders/referenced/in.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) ⇒ Document

This builder either takes a foreign key and queries for the object or a document, where it will just return it.

Examples:

Build the document.

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
# File 'lib/mongoid/relations/builders/referenced/in.rb', line 17

def build(type = nil)
  return object unless query?
  model = type ? type.constantize : .klass
  .criteria(object, model).from_map_or_db
end