Class: Mongoid::Relations::One
- Defined in:
- lib/mongoid/relations/one.rb
Overview
This is the superclass for one to one relations and defines the common behaviour or those proxies.
Direct Known Subclasses
Embedded::In, Embedded::One, Referenced::In, Referenced::One
Instance Attribute Summary
Attributes inherited from Proxy
#base, #loaded, #metadata, #target
Instance Method Summary collapse
-
#load!(options = {}) ⇒ One
Will load the target into an array if the target had not already been loaded.
-
#substitute(new_target, options = {}) ⇒ Document?
Substitutes the supplied target documents for the existing document in the relation.
Methods inherited from Proxy
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Mongoid::Relations::Proxy
Instance Method Details
#load!(options = {}) ⇒ One
Will load the target into an array if the target had not already been loaded.
18 19 20 21 22 23 24 25 |
# File 'lib/mongoid/relations/one.rb', line 18 def load!( = {}) tap do |relation| unless relation.loaded? relation.bind() relation.loaded = true end end end |
#substitute(new_target, options = {}) ⇒ Document?
Substitutes the supplied target documents for the existing document in the relation.
38 39 40 41 42 43 44 |
# File 'lib/mongoid/relations/one.rb', line 38 def substitute(new_target, = {}) old_target = target tap do |relation| relation.target = new_target new_target ? bind() : (unbind(old_target, ) and return nil) end end |