123456789_123456789_123456789_123456789_123456789_

Class: Mongoid::Association::One

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Proxy, Forwardable
Instance Chain:
Inherits: Mongoid::Association::Proxy
Defined in: lib/mongoid/association/one.rb

Overview

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

Constant Summary

Proxy - Inherited

KEEPER_METHODS

Class Method Summary

Proxy - Inherited

.apply_ordering

Apply ordering to the criteria if it was defined on the association.

.new

Sets the target and the association metadata properties.

Instance Attribute Summary

Proxy - Inherited

#_association,
#_base

Model instance for the base of the association.

#_target

Model instance for one to one associations, or array of model instances for one to many associations, for the target of the association.

::Mongoid::Threaded::Lifecycle - Included

#_assigning

Begin the assignment of attributes.

#_assigning?

Is the current thread in assigning mode?

#_binding

Execute a block in binding mode.

#_binding?

Is the current thread in binding mode?

#_building

Execute a block in building mode.

#_building?

Is the current thread in building mode?

#_creating?

Is the current thread in creating mode?

#_loading

Execute a block in loading mode.

#_loading?

Is the current thread in loading mode?

Instance Method Summary

Proxy - Inherited

#extend_proxies

Allow extension to be an array and extend each module.

#extend_proxy,
#klass

Get the class from the association, or return nil if no association present.

#reset_unloaded

Resets the criteria inside the association proxy.

#substitutable

The default substitutable object for an association proxy is the clone of the target.

Marshalable - Included

#marshal_dump

Provides the data needed to Marshal.dump an association proxy.

#marshal_load

Takes the provided data and sets it back on the proxy.

Constructor Details

This class inherits a constructor from Mongoid::Association::Proxy

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.

[ GitHub ]

  
# File 'lib/mongoid/association/one.rb', line 49

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 succeeded.

[ GitHub ]

  
# File 'lib/mongoid/association/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:

[ GitHub ]

  
# File 'lib/mongoid/association/one.rb', line 27

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.

[ GitHub ]

  
# File 'lib/mongoid/association/one.rb', line 39

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