Class: Mongoid::Associations::EmbeddedIn
- Defined in:
- lib/mongoid/associations/embedded_in.rb
Overview
Represents an association that is embedded within another document in the database, either as one or many.
Instance Attribute Summary
Attributes inherited from Proxy
Class Method Summary collapse
-
.instantiate(document, options) ⇒ Object
Creates the new association by setting the internal document as the passed in Document.
-
.macro ⇒ Object
Returns the macro used to create the association.
-
.update(target, child, options) ⇒ Object
Perform an update of the relationship of the parent and child.
Instance Method Summary collapse
-
#find(id) ⇒ Object
Returns the parent document.
-
#initialize(target, options) ⇒ EmbeddedIn
constructor
Creates the new association by setting the internal target as the passed in Document.
Methods inherited from Proxy
Constructor Details
#initialize(target, options) ⇒ EmbeddedIn
Creates the new association by setting the internal target as the passed in Document. This should be the parent.
All method calls on this object will then be delegated to the internal document itself.
Options:
target: The parent Document
options: The association options
19 20 21 22 |
# File 'lib/mongoid/associations/embedded_in.rb', line 19 def initialize(target, ) @target, @options = target, extends() end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Mongoid::Associations::Proxy
Class Method Details
.instantiate(document, options) ⇒ Object
Creates the new association by setting the internal document as the passed in Document. This should be the parent.
Options:
document: The parent Document
options: The association options
40 41 42 43 |
# File 'lib/mongoid/associations/embedded_in.rb', line 40 def instantiate(document, ) target = document._parent target.nil? ? nil : new(target, ) end |
.macro ⇒ Object
Returns the macro used to create the association.
46 47 48 |
# File 'lib/mongoid/associations/embedded_in.rb', line 46 def macro :embedded_in end |
.update(target, child, options) ⇒ Object
Perform an update of the relationship of the parent and child. This is initialized by setting a parent object as the association on the Document
. Will properly set an embeds_one or an embeds_many.
Returns:
A new EmbeddedIn
association proxy.
57 58 59 60 61 |
# File 'lib/mongoid/associations/embedded_in.rb', line 57 def update(target, child, ) child.parentize(target, determine_name(target, )) child.notify instantiate(child, ) end |
Instance Method Details
#find(id) ⇒ Object
Returns the parent document. The id param is present for compatibility with rails, however this could be overwritten in the future.
27 28 29 |
# File 'lib/mongoid/associations/embedded_in.rb', line 27 def find(id) @target end |