Class: Mongoid::Associations::HasOneAssociation

Inherits:
Object
  • Object
show all
Defined in:
lib/mongoid/associations/has_one_association.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(association_name, document) ⇒ HasOneAssociation

Creates the new association by finding the attributes in the parent document with its name, and instantiating a new document for it.

All method calls on this object will then be delegated to the internal document itself.



14
15
16
17
18
19
20
# File 'lib/mongoid/associations/has_one_association.rb', line 14

def initialize(association_name, document)
  klass = association_name.to_s.titleize.constantize
  attributes = document.attributes[association_name]
  @document = klass.new(attributes)
  @document.parent = document
  decorate!
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document.



5
6
7
# File 'lib/mongoid/associations/has_one_association.rb', line 5

def document
  @document
end