Class: Mongoid::Relations::Builders::Referenced::One

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

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) ⇒ Document

This builder either takes an _id or an object and queries for the inverse side using the id or sets the object.

Examples:

Build the document.

Builder.new(meta, attrs).build

Parameters:

  • type (String) (defaults to: nil)

    The type of document to query for.

Returns:



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

def build(type = nil)
  return object unless query?
  .klass.first(
    :conditions => { .foreign_key => object }
  )
end