Class: Mongoid::Association::Referenced::HasOne::Proxy
- Defined in:
- lib/mongoid/association/referenced/has_one/proxy.rb
Overview
This class defines the behavior for all associations that are a one-to-one between documents in different collections.
Instance Attribute Summary
Attributes inherited from Proxy
#_association, #_base, #_target
Class Method Summary collapse
- .eager_loader(association, docs) ⇒ Object
-
.embedded? ⇒ false
Returns true if the association is an embedded one.
Instance Method Summary collapse
-
#initialize(base, target, association) ⇒ Proxy
constructor
Instantiate a new references_one association.
-
#nullify ⇒ Object
Removes the association between the base document and the target document by deleting the foreign key and the reference, orphaning the target document in the process.
-
#substitute(replacement) ⇒ One
Substitutes the supplied target document for the existing document in the association.
Methods inherited from One
#__evolve_object_id__, #clear, #in_memory, #respond_to?
Methods inherited from Proxy
apply_ordering, #extend_proxies, #init, #klass, #reset_unloaded, #substitutable
Methods included from Marshalable
Constructor Details
#initialize(base, target, association) ⇒ Proxy
Instantiate a new references_one association. Will set the foreign key and the base on the inverse object.
21 22 23 24 25 26 27 28 |
# File 'lib/mongoid/association/referenced/has_one/proxy.rb', line 21 def initialize(base, target, association) init(base, target, association) do raise_mixed if klass. && !klass.cyclic? characterize_one(_target) bind_one _target.save if persistable? end end |
Class Method Details
.eager_loader(association, docs) ⇒ Object
89 90 91 |
# File 'lib/mongoid/association/referenced/has_one/proxy.rb', line 89 def eager_loader(association, docs) Eager.new(association, docs) end |
.embedded? ⇒ false
Returns true if the association is an embedded one. In this case always false.
100 101 102 |
# File 'lib/mongoid/association/referenced/has_one/proxy.rb', line 100 def false end |
Instance Method Details
#nullify ⇒ Object
Removes the association between the base document and the target document by deleting the foreign key and the reference, orphaning the target document in the process.
36 37 38 39 |
# File 'lib/mongoid/association/referenced/has_one/proxy.rb', line 36 def nullify unbind_one _target.save end |
#substitute(replacement) ⇒ One
Substitutes the supplied target document for the existing document in the association. If the new target is nil, perform the necessary deletion.
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/mongoid/association/referenced/has_one/proxy.rb', line 51 def substitute(replacement) if self != replacement unbind_one if persistable? if _association.destructive? send(_association.dependent) else save if persisted? end end end HasOne::Proxy.new(_base, replacement, _association) if replacement end |