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

#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



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

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



31
32
33
# File 'lib/mongoid/relations/one.rb', line 31

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