Class: Mongoid::Association::One

Inherits:
Proxy
  • Object
show all
Defined in:
build/mongoid-7.3/lib/mongoid/association/one.rb

Overview

This is the superclass for one to one relations and defines the common behavior or those proxies.

Instance Attribute Summary

Attributes inherited from Proxy

#_association, #_base, #_target

Instance Method Summary collapse

Methods inherited from Proxy

apply_ordering, #extend_proxies, #init, #klass, #reset_unloaded, #substitutable

Methods included from Marshalable

#marshal_dump, #marshal_load

Instance Method Details

#__evolve_object_id__Object

Evolve the proxy document into an object id.

Examples:

Evolve the proxy document.

proxy.__evolve_object_id__

Returns:

  • (Object)

    The proxy document’s id.

Since:

  • 4.0.0



57
58
59
# File 'build/mongoid-7.3/lib/mongoid/association/one.rb', line 57

def __evolve_object_id__
  _target._id
end

#cleartrue, false

Clear this relation - same as calling #delete on the document.

Examples:

Clear the relation.

relation.clear

Returns:

  • (true, false)

    If the delete suceeded.

Since:

  • 3.0.0



19
20
21
# File 'build/mongoid-7.3/lib/mongoid/association/one.rb', line 19

def clear
  _target.delete
end

#in_memoryArray<Document>

Get all the documents in the relation that are loaded into memory.

Examples:

Get the in memory documents.

relation.in_memory

Returns:

  • (Array<Document>)

    The documents in memory.

Since:

  • 2.1.0



31
32
33
# File 'build/mongoid-7.3/lib/mongoid/association/one.rb', line 31

def in_memory
  [ _target ]
end

#respond_to?(name, include_private = false) ⇒ true, false

Since method_missing is overridden we should override this as well.

Examples:

Does the proxy respond to the method?

relation.respond_to?(:name)

Parameters:

  • name (Symbol)

    The method name.

Returns:

  • (true, false)

    If the proxy responds to the method.

Since:

  • 2.1.8



45
46
47
# File 'build/mongoid-7.3/lib/mongoid/association/one.rb', line 45

def respond_to?(name, include_private = false)
  _target.respond_to?(name, include_private) || super
end