Class: Mongoid::Association::Embedded::EmbeddedIn::Proxy
- Defined in:
- lib/mongoid/association/embedded/embedded_in/proxy.rb
Overview
Transparent proxy for embedded_in associations. An instance of this class is returned when calling the association getter method on the child document. This class inherits from Mongoid::Association::Proxy and forwards most of its methods to the target of the association, i.e. the parent document.
Constant Summary
Constants inherited from Proxy
Instance Attribute Summary
Attributes inherited from Proxy
#_association, #_base, #_target
Class Method Summary collapse
-
.eager_loader(associations, docs) ⇒ Mongoid::Association::Embedded::Eager
Returns the eager loader for this association.
-
.embedded? ⇒ true
Returns true if the association is an embedded one.
-
.path(document) ⇒ Root
Get the path calculator for the supplied document.
Instance Method Summary collapse
-
#initialize(base, target, association) ⇒ In
constructor
Instantiate a new embedded_in association.
-
#substitute(replacement) ⇒ Document | nil
Substitutes the supplied target documents 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, #klass, #reset_unloaded, #substitutable
Methods included from Marshalable
Constructor Details
#initialize(base, target, association) ⇒ In
Instantiate a new embedded_in association.
24 25 26 27 28 29 |
# File 'lib/mongoid/association/embedded/embedded_in/proxy.rb', line 24 def initialize(base, target, association) super do characterize_one(_target) bind_one end end |
Class Method Details
.eager_loader(associations, docs) ⇒ Mongoid::Association::Embedded::Eager
Returns the eager loader for this association.
95 96 97 |
# File 'lib/mongoid/association/embedded/embedded_in/proxy.rb', line 95 def eager_loader(associations, docs) Eager.new(associations, docs) end |
.embedded? ⇒ true
Returns true if the association is an embedded one. In this case always true.
106 107 108 |
# File 'lib/mongoid/association/embedded/embedded_in/proxy.rb', line 106 def true end |
Instance Method Details
#substitute(replacement) ⇒ Document | nil
Substitutes the supplied target documents for the existing document in the association.
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/mongoid/association/embedded/embedded_in/proxy.rb', line 40 def substitute(replacement) unbind_one unless replacement _base.delete if persistable? return nil end _base.new_record = true replacement = Factory.build(klass, replacement) if replacement.is_a?(::Hash) self._target = replacement bind_one self end |