Module: Mongoid::Association::Referenced::BelongsTo::Buildable

Included in:
Mongoid::Association::Referenced::BelongsTo
Defined in:
build/mongoid-7.0/lib/mongoid/association/referenced/belongs_to/buildable.rb

Overview

The Builder behavior for belongs_to associations.

Since:

  • 7.0

Instance Method Summary collapse

Instance Method Details

#build(base, object, type = nil) ⇒ Document

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

Examples:

Build the document.

relation.build(meta, attrs)

Parameters:

  • base (Object)

    The base object.

  • object (Object)

    The object to use to build the relation.

  • type (String) (defaults to: nil)

    The type of the relation.

Returns:

Since:

  • 7.0



23
24
25
26
# File 'build/mongoid-7.0/lib/mongoid/association/referenced/belongs_to/buildable.rb', line 23

def build(base, object, type = nil)
  return object unless query?(object)
  execute_query(object, type)
end