Module: Mongoid::Association::Referenced::HasOne::Buildable

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

Overview

The Builder behavior for has_one 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 after clearing the associated object.

Returns:

Since:

  • 7.0



17
18
19
20
21
22
23
24
25
26
# File 'build/mongoid-7.0/lib/mongoid/association/referenced/has_one/buildable.rb', line 17

def build(base, object, type = nil)
  if query?(object)
    if !base.new_record?
      execute_query(object, base)
    end
  else
    clear_associated(object)
    object
  end
end