Class: ActiveRecord::Associations::JoinDependency::JoinPart
- Inherits:
 - 
      Object
      
        
- Object
 - ActiveRecord::Associations::JoinDependency::JoinPart
 
 
- Includes:
 - Enumerable
 
- Defined in:
 - lib/active_record/associations/join_dependency/join_part.rb
 
Overview
A JoinPart represents a part of a JoinDependency. It is inherited by JoinBase and JoinAssociation. A JoinBase represents the Active Record which everything else is being joined onto. A JoinAssociation represents an association which is joining to the base. A JoinAssociation may result in more than one actual join operations (for example a has_and_belongs_to_many JoinAssociation would result in two; one for the join table and one for the target table).
Direct Known Subclasses
Instance Attribute Summary collapse
- 
  
    
      #base_klass  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
The Active Record class which this join part is associated 'about'; for a JoinBase this is the actual base model, for a JoinAssociation this is the target model of the association.
 - 
  
    
      #children  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
The Active Record class which this join part is associated 'about'; for a JoinBase this is the actual base model, for a JoinAssociation this is the target model of the association.
 
Instance Method Summary collapse
- #each {|_self| ... } ⇒ Object
 - #each_children(&block) ⇒ Object
 - #extract_record(row, column_names_with_alias) ⇒ Object
 - 
  
    
      #initialize(base_klass, children)  ⇒ JoinPart 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of JoinPart.
 - #instantiate(row, aliases, column_types = {}, &block) ⇒ Object
 - #match?(other) ⇒ Boolean
 - 
  
    
      #table  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
An Arel::Table for the active_record.
 
Constructor Details
#initialize(base_klass, children) ⇒ JoinPart
Returns a new instance of JoinPart.
      22 23 24 25  | 
    
      # File 'lib/active_record/associations/join_dependency/join_part.rb', line 22 def initialize(base_klass, children) @base_klass = base_klass @children = children end  | 
  
Instance Attribute Details
#base_klass ⇒ Object (readonly)
The Active Record class which this join part is associated 'about'; for a JoinBase this is the actual base model, for a JoinAssociation this is the target model of the association.
      18 19 20  | 
    
      # File 'lib/active_record/associations/join_dependency/join_part.rb', line 18 def base_klass @base_klass end  | 
  
#children ⇒ Object (readonly)
The Active Record class which this join part is associated 'about'; for a JoinBase this is the actual base model, for a JoinAssociation this is the target model of the association.
      18 19 20  | 
    
      # File 'lib/active_record/associations/join_dependency/join_part.rb', line 18 def children @children end  | 
  
Instance Method Details
#each {|_self| ... } ⇒ Object
      31 32 33 34  | 
    
      # File 'lib/active_record/associations/join_dependency/join_part.rb', line 31 def each(&block) yield self children.each { |child| child.each(&block) } end  | 
  
#each_children(&block) ⇒ Object
      36 37 38 39 40 41  | 
    
      # File 'lib/active_record/associations/join_dependency/join_part.rb', line 36 def each_children(&block) children.each do |child| yield self, child child.each_children(&block) end end  | 
  
#extract_record(row, column_names_with_alias) ⇒ Object
      48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63  | 
    
      # File 'lib/active_record/associations/join_dependency/join_part.rb', line 48 def extract_record(row, column_names_with_alias) # This code is performance critical as it is called per row. # see: https://github.com/rails/rails/pull/12185 hash = {} index = 0 length = column_names_with_alias.length while index < length column = column_names_with_alias[index] hash[column.name] = row[column.alias] index += 1 end hash end  | 
  
#instantiate(row, aliases, column_types = {}, &block) ⇒ Object
      65 66 67  | 
    
      # File 'lib/active_record/associations/join_dependency/join_part.rb', line 65 def instantiate(row, aliases, column_types = {}, &block) base_klass.instantiate(extract_record(row, aliases), column_types, &block) end  | 
  
#match?(other) ⇒ Boolean
      27 28 29  | 
    
      # File 'lib/active_record/associations/join_dependency/join_part.rb', line 27 def match?(other) self.class == other.class end  | 
  
#table ⇒ Object
An Arel::Table for the active_record
      44 45 46  | 
    
      # File 'lib/active_record/associations/join_dependency/join_part.rb', line 44 def table raise NotImplementedError end  |