Class: Mongoid::Association::Referenced::BelongsTo::Proxy
- Includes:
- Evolvable
- Defined in:
- build/mongoid-7.3/lib/mongoid/association/referenced/belongs_to/proxy.rb
Overview
This class handles all behavior for associations that are either one-to-many or one-to-one, where the foreign key is stored on this side of the association and the reference is to document(s) in another collection.
Instance Attribute Summary
Attributes inherited from Proxy
#_association, #_base, #_target
Class Method Summary collapse
-
.eager_loader(association, docs) ⇒ Object
Get the Eager object for this type of association.
-
.embedded? ⇒ false
Returns true if the association is an embedded one.
Instance Method Summary collapse
-
#initialize(base, target, association) ⇒ Proxy
constructor
Instantiate a new belongs_to association proxy.
-
#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) ⇒ self?
Substitutes the supplied target documents for the existing document in the association.
Methods included from Evolvable
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 belongs_to association proxy.
25 26 27 28 29 30 |
# File 'build/mongoid-7.3/lib/mongoid/association/referenced/belongs_to/proxy.rb', line 25 def initialize(base, target, association) init(base, target, association) do characterize_one(_target) bind_one end end |
Class Method Details
.eager_loader(association, docs) ⇒ Object
Get the Eager object for this type of association.
117 118 119 |
# File 'build/mongoid-7.3/lib/mongoid/association/referenced/belongs_to/proxy.rb', line 117 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.
130 131 132 |
# File 'build/mongoid-7.3/lib/mongoid/association/referenced/belongs_to/proxy.rb', line 130 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.
39 40 41 42 |
# File 'build/mongoid-7.3/lib/mongoid/association/referenced/belongs_to/proxy.rb', line 39 def nullify unbind_one _target.save end |
#substitute(replacement) ⇒ self?
Substitutes the supplied target documents for the existing document in the association.
55 56 57 58 59 60 61 62 |
# File 'build/mongoid-7.3/lib/mongoid/association/referenced/belongs_to/proxy.rb', line 55 def substitute(replacement) unbind_one if replacement self._target = normalize(replacement) bind_one self end end |