Class: Mongoid::Association::Proxy
| Relationships & Source Files | |
| Extension / Inclusion / Inheritance Descendants | |
| Subclasses: | |
| Super Chains via Extension / Inclusion / Inheritance | |
| Class Chain: 
          self,
          Forwardable
         | |
| Instance Chain: | |
| Inherits: | Object | 
| 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.
Constant Summary
- 
    KEEPER_METHODS =
    # File 'lib/mongoid/association/proxy.rb', line 15specific methods to prevent from being undefined %i[ send object_id equal? respond_to? respond_to_missing? tap public_send extend_proxy extend_proxies ].freeze 
Class Method Summary
- 
    
      .apply_ordering(criteria, association)  ⇒ Criteria 
    
    Apply ordering to the criteria if it was defined on the association. 
- 
    
      .new(base, target, association) {|_self| ... } ⇒ Proxy 
    
    constructor
    Sets the target and the association metadata properties. 
Instance Attribute Summary
- #_association rw
- 
    
      #_base  
    
    rw
    Model instance for the base of the association. 
- 
    
      #_target  
      (also: #in_memory)
    
    rw
    Model instance for one to one associations, or array of model instances for one to many associations, for the target of the association. 
::Mongoid::Threaded::Lifecycle - Included
| #_assigning | Begin the assignment of attributes. | 
| #_assigning? | Is the current thread in assigning mode? | 
| #_binding | Execute a block in binding mode. | 
| #_binding? | Is the current thread in binding mode? | 
| #_building | Execute a block in building mode. | 
| #_building? | Is the current thread in building mode? | 
| #_creating? | Is the current thread in creating mode? | 
| #_loading | Execute a block in loading mode. | 
| #_loading? | Is the current thread in loading mode? | 
Instance Method Summary
- 
    
      #extend_proxies(*extension)  
    
    Allow extension to be an array and extend each module. 
- #extend_proxy
- 
    
      #klass  ⇒ Class 
    
    Get the class from the association, or return nil if no association present. 
- 
    
      #reset_unloaded  
    
    Resets the criteria inside the association proxy. 
- 
    
      #substitutable  ⇒ Object 
    
    The default substitutable object for an association proxy is the clone of the target. 
Marshalable - Included
| #marshal_dump | Provides the data needed to Marshal.dump an association proxy. | 
| #marshal_load | Takes the provided data and sets it back on the proxy. | 
Constructor Details
    .new(base, target, association) {|_self| ... } ⇒ Proxy 
  
Sets the target and the association metadata properties.
# File 'lib/mongoid/association/proxy.rb', line 60
def initialize(base, target, association) @_base, @_target, @_association = base, target, association yield(self) if block_given? extend_proxies(association.extension) if association.extension end
Class Method Details
.apply_ordering(criteria, association) ⇒ Criteria
Apply ordering to the criteria if it was defined on the association.
# File 'lib/mongoid/association/proxy.rb', line 206
def apply_ordering(criteria, association) association.order ? criteria.order_by(association.order) : criteria end
Instance Attribute Details
#_association (rw)
[ GitHub ]# File 'lib/mongoid/association/proxy.rb', line 41
attr_accessor :_association
#_base (rw)
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.
# File 'lib/mongoid/association/proxy.rb', line 39
attr_accessor :_base
#_target (rw) Also known as: #in_memory
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.
# File 'lib/mongoid/association/proxy.rb', line 48
attr_accessor :_target
Instance Method Details
#extend_proxies(*extension)
Allow extension to be an array and extend each module
# File 'lib/mongoid/association/proxy.rb', line 67
def extend_proxies(*extension) extension.flatten.each { |ext| extend_proxy(ext) } end
#extend_proxy
[ GitHub ]# File 'lib/mongoid/association/proxy.rb', line 12
alias extend_proxy extend
    #klass  ⇒ Class 
  
Get the class from the association, or return nil if no association present.
# File 'lib/mongoid/association/proxy.rb', line 77
def klass _association&.klass end
#reset_unloaded
Resets the criteria inside the association proxy. Used by many to many associations to keep the underlying ids array in sync.
# File 'lib/mongoid/association/proxy.rb', line 86
def reset_unloaded _target.reset_unloaded(criteria) end
    #substitutable  ⇒ Object 
  
The default substitutable object for an association proxy is the clone of the target.
# File 'lib/mongoid/association/proxy.rb', line 97
def substitutable _target end