Class: Mongoid::Associations::HasOneAssociation
- Includes:
- Decorator
- Defined in:
- lib/mongoid/associations/has_one_association.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#initialize(association_name, document) ⇒ HasOneAssociation
constructor
Creates the new association by finding the attributes in the parent document with its name, and instantiating a new document for it.
Methods included from Decorator
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 |