Class: Mongoid::Relations::Proxy
- Inherits:
-
Object
- Object
- Mongoid::Relations::Proxy
- Includes:
- Threaded::Lifecycle
- Defined in:
- lib/mongoid/relations/proxy.rb
Overview
This class is the superclass for all relation proxy objects, and contains common behaviour for all of them.
Instance Attribute Summary (collapse)
-
- (Object) base
Returns the value of attribute base.
-
- (Object) loaded
Returns the value of attribute loaded.
-
- (Object) metadata
Returns the value of attribute metadata.
-
- (Object) target
Returns the value of attribute target.
Class Method Summary (collapse)
-
+ (Criteria) eager_load_ids(metadata, ids)
Get the criteria that is used to eager load a relation of this type.
Instance Method Summary (collapse)
-
- (Object) init(base, target, metadata) {|_self| ... }
Convenience for setting the target and the metadata properties since all proxies will need to do this.
-
- (Object) substitutable
The default substitutable object for a relation proxy is the clone of the target.
-
- (Document) with(options)
Tell the next persistance operation to store in a specific collection, database or session.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
- (Object) method_missing(name, *args, &block) (protected)
Default behavior of method missing should be to delegate all calls to the target of the proxy. This can be overridden in special cases.
116 117 118 |
# File 'lib/mongoid/relations/proxy.rb', line 116 def method_missing(name, *args, &block) target.send(name, *args, &block) end |
Instance Attribute Details
- (Object) base
Returns the value of attribute base
18 19 20 |
# File 'lib/mongoid/relations/proxy.rb', line 18 def base @base end |
- (Object) loaded
Returns the value of attribute loaded
18 19 20 |
# File 'lib/mongoid/relations/proxy.rb', line 18 def loaded @loaded end |
- (Object) metadata
Returns the value of attribute metadata
18 19 20 |
# File 'lib/mongoid/relations/proxy.rb', line 18 def @metadata end |
- (Object) target
Returns the value of attribute target
18 19 20 |
# File 'lib/mongoid/relations/proxy.rb', line 18 def target @target end |
Class Method Details
+ (Criteria) eager_load_ids(metadata, ids)
Get the criteria that is used to eager load a relation of this type.
162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/mongoid/relations/proxy.rb', line 162 def eager_load_ids(, ids) cleared = false klass, foreign_key = .klass, .foreign_key klass.any_in(foreign_key => ids).each do |doc| selector = { foreign_key => doc.send(foreign_key) } unless cleared IdentityMap.clear_many(klass, selector) cleared = true end yield(doc, foreign_key => doc.send(foreign_key)) end end |
Instance Method Details
- (Object) init(base, target, metadata) {|_self| ... }
Convenience for setting the target and the metadata properties since all proxies will need to do this.
36 37 38 39 40 |
# File 'lib/mongoid/relations/proxy.rb', line 36 def init(base, target, ) @base, @target, @metadata = base, target, yield(self) if block_given? extend_proxy(.extension) if .extension? end |
- (Object) substitutable
The default substitutable object for a relation proxy is the clone of the target.
51 52 53 |
# File 'lib/mongoid/relations/proxy.rb', line 51 def substitutable target end |
- (Document) with(options)
Tell the next persistance operation to store in a specific collection, database or session.
79 80 81 82 |
# File 'lib/mongoid/relations/proxy.rb', line 79 def with() Threaded.(klass, ) self end |