Class: Mongoid::Relations::Builders::Embedded::One

Inherits:
Mongoid::Relations::Builder show all
Defined in:
lib/mongoid/relations/builders/embedded/one.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

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.

Examples:

Build the document.

Builder.new(meta, attrs).build

Parameters:

  • type (String) (defaults to: nil)

    Not used in this context.

Returns:

Since:

  • 2.0.0.rc.1



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

def build(type = nil)
  return object unless object.is_a?(Hash)
  if _loading? && base.persisted?
    Factory.from_db(klass, object)
  else
    Factory.build(klass, object)
  end
end