Class: Mongoid::Association::Proxy
- Inherits:
-
Object
- Object
- Mongoid::Association::Proxy
- Extended by:
- Forwardable
- Includes:
- Marshalable, Threaded::Lifecycle
- Defined in:
- lib/mongoid/association/proxy.rb
Overview
This class is the superclass for all association proxy objects, and contains common behavior for all of them.
Instance Attribute Summary collapse
-
#_association ⇒ Object
Returns the value of attribute _association.
-
#_base ⇒ Object
Model instance for the base of the association.
-
#_target ⇒ Object
Model instance for one to one associations, or array of model instances for one to many associations, for the target of the association.
Class Method Summary collapse
-
.apply_ordering(criteria, association) ⇒ Criteria
Apply ordering to the criteria if it was defined on the association.
Instance Method Summary collapse
-
#extend_proxies(*extension) ⇒ Object
Allow extension to be an array and extend each module.
-
#init(base, target, association) {|_self| ... } ⇒ Object
Convenience for setting the target and the association metadata properties since all proxies will need to do this.
-
#klass ⇒ Class
Get the class from the association, or return nil if no association present.
-
#reset_unloaded ⇒ Object
Resets the criteria inside the association proxy.
-
#substitutable ⇒ Object
The default substitutable object for an association proxy is the clone of the target.
Methods included from Marshalable
Instance Attribute Details
#_association ⇒ Object
Returns the value of attribute _association.
30 31 32 |
# File 'lib/mongoid/association/proxy.rb', line 30 def _association @_association end |
#_base ⇒ Object
Model instance for the base of the association.
For example, if a Post embeds_many Comments, _base is a particular instance of the Post model.
28 29 30 |
# File 'lib/mongoid/association/proxy.rb', line 28 def _base @_base end |
#_target ⇒ Object
Model instance for one to one associations, or array of model instances for one to many associations, for the target of the association.
For example, if a Post embeds_many Comments, _target is an array of Comment models embedded in a particular Post.
37 38 39 |
# File 'lib/mongoid/association/proxy.rb', line 37 def _target @_target end |
Class Method Details
.apply_ordering(criteria, association) ⇒ Criteria
Apply ordering to the criteria if it was defined on the association.
194 195 196 |
# File 'lib/mongoid/association/proxy.rb', line 194 def apply_ordering(criteria, association) association.order ? criteria.order_by(association.order) : criteria end |
Instance Method Details
#extend_proxies(*extension) ⇒ Object
Allow extension to be an array and extend each module
60 61 62 |
# File 'lib/mongoid/association/proxy.rb', line 60 def extend_proxies(*extension) extension.flatten.each {|ext| extend_proxy(ext) } end |
#init(base, target, association) {|_self| ... } ⇒ Object
Convenience for setting the target and the association metadata properties since all proxies will need to do this.
53 54 55 56 57 |
# File 'lib/mongoid/association/proxy.rb', line 53 def init(base, target, association) @_base, @_target, @_association = base, target, association yield(self) if block_given? extend_proxies(association.extension) if association.extension end |
#klass ⇒ Class
Get the class from the association, or return nil if no association present.
70 71 72 |
# File 'lib/mongoid/association/proxy.rb', line 70 def klass _association ? _association.klass : nil end |
#reset_unloaded ⇒ Object
Resets the criteria inside the association proxy. Used by many to many associations to keep the underlying ids array in sync.
79 80 81 |
# File 'lib/mongoid/association/proxy.rb', line 79 def reset_unloaded _target.reset_unloaded(criteria) end |
#substitutable ⇒ Object
The default substitutable object for an association proxy is the clone of the target.
90 91 92 |
# File 'lib/mongoid/association/proxy.rb', line 90 def substitutable _target end |