Class: Mongoid::Relations::One

Inherits:
Proxy show all
Defined in:
lib/mongoid/relations/one.rb

Overview

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

Instance Attribute Summary

Attributes inherited from Proxy

#base, #loaded, #metadata, #target

Instance Method Summary collapse

Methods inherited from Proxy

#init, #substitutable

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Mongoid::Relations::Proxy

Instance Method Details

#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



17
18
19
# File 'lib/mongoid/relations/one.rb', line 17

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:

Since:

  • 2.1.0



29
30
31
# File 'lib/mongoid/relations/one.rb', line 29

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



43
44
45
# File 'lib/mongoid/relations/one.rb', line 43

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