Class: Mongoid::Association::Referenced::BelongsTo::Proxy
- Includes:
- Evolvable
- Defined in:
- lib/mongoid/association/referenced/belongs_to/proxy.rb
Overview
Transparent proxy for belong_to associations. An instance of this class is returned when calling the association getter method on the subject document. This class inherits from Mongoid::Association::Proxy and forwards most of its methods to the target of the association, i.e. the document on the opposite-side collection which must be loaded.
Constant Summary
Constants inherited from Proxy
Instance Attribute Summary
Attributes inherited from Proxy
#_association, #_base, #_target
Class Method Summary collapse
-
.eager_loader(association, docs) ⇒ Mongoid::Association::Referenced::BelongsTo::Eager
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 | nil
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, #klass, #reset_unloaded, #substitutable
Methods included from Marshalable
Constructor Details
#initialize(base, target, association) ⇒ Proxy
Instantiate a new belongs_to association proxy.
26 27 28 29 30 31 |
# File 'lib/mongoid/association/referenced/belongs_to/proxy.rb', line 26 def initialize(base, target, association) super do characterize_one(_target) bind_one end end |
Class Method Details
.eager_loader(association, docs) ⇒ Mongoid::Association::Referenced::BelongsTo::Eager
Get the Eager object for this type of association.
110 111 112 |
# File 'lib/mongoid/association/referenced/belongs_to/proxy.rb', line 110 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.
121 122 123 |
# File 'lib/mongoid/association/referenced/belongs_to/proxy.rb', line 121 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 'lib/mongoid/association/referenced/belongs_to/proxy.rb', line 39 def nullify unbind_one _target.save end |
#substitute(replacement) ⇒ self | nil
Substitutes the supplied target documents for the existing document in the association.
53 54 55 56 57 58 59 60 |
# File 'lib/mongoid/association/referenced/belongs_to/proxy.rb', line 53 def substitute(replacement) unbind_one return unless replacement self._target = normalize(replacement) bind_one self end |