Class: Mongoid::Associations::HasOneAssociation

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

Overview

:nodoc:

Instance Method Summary collapse

Methods included from Decorator

included

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