123456789_123456789_123456789_123456789_123456789_

Class: ActiveRecord::Associations::JoinDependency::JoinPart

Do not use. This class is for internal use only.
Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
Inherits: Object
Defined in: activerecord/lib/active_record/associations/join_dependency/join_part.rb

Overview

A JoinPart represents a part of a ::ActiveRecord::Associations::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).

Class Method Summary

Instance Attribute Summary

::Enumerable - Included

#many?

Returns true if the enumerable has more than 1 element.

Instance Method Summary

::Enumerable - Included

#compact_blank

Returns a new ::Array without the blank items.

#exclude?

The negative of the Enumerable#include?.

#excluding

Returns a copy of the enumerable excluding the specified elements.

#in_order_of

Returns a new ::Array where the order has been set to that provided in the series, based on the key of the objects in the original enumerable.

#including

Returns a new array that includes the passed elements.

#index_by

Convert an enumerable to a hash, using the block result as the key and the element as the value.

#index_with

Convert an enumerable to a hash, using the element as the key and the block result as the value.

#maximum

Calculates the maximum from the extracted elements.

#minimum

Calculates the minimum from the extracted elements.

#pick

Extract the given key from the first element in the enumerable.

#pluck

Extract the given key from each element in the enumerable.

#sole

Returns the sole item in the enumerable.

#without
#as_json

::ActiveSupport::EnumerableCoreExt::Constants - Included

Constructor Details

.new(base_klass, children) ⇒ JoinPart

[ GitHub ]

  
# File 'activerecord/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

#attribute_types (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/associations/join_dependency/join_part.rb', line 20

delegate :table_name, :column_names, :primary_key, :attribute_types, to: :base_klass

#base_klass (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.

[ GitHub ]

  
# File 'activerecord/lib/active_record/associations/join_dependency/join_part.rb', line 18

attr_reader :base_klass, :children

#children (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.

[ GitHub ]

  
# File 'activerecord/lib/active_record/associations/join_dependency/join_part.rb', line 18

attr_reader :base_klass, :children

#column_names (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/associations/join_dependency/join_part.rb', line 20

delegate :table_name, :column_names, :primary_key, :attribute_types, to: :base_klass

#primary_key (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/associations/join_dependency/join_part.rb', line 20

delegate :table_name, :column_names, :primary_key, :attribute_types, to: :base_klass

#table_name (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/associations/join_dependency/join_part.rb', line 20

delegate :table_name, :column_names, :primary_key, :attribute_types, to: :base_klass

Instance Method Details

#each {|_self| ... }

Yields:

  • (_self)

Yield Parameters:

  • _self (JoinPart)

    the object that the method was called on

[ GitHub ]

  
# File 'activerecord/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)

[ GitHub ]

  
# File 'activerecord/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)

[ GitHub ]

  
# File 'activerecord/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)

[ GitHub ]

  
# File 'activerecord/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

[ GitHub ]

  
# File 'activerecord/lib/active_record/associations/join_dependency/join_part.rb', line 27

def match?(other)
  self.class == other.class
end

#table

An ::Arel::Table for the active_record

Raises:

  • (NotImplementedError)
[ GitHub ]

  
# File 'activerecord/lib/active_record/associations/join_dependency/join_part.rb', line 44

def table
  raise NotImplementedError
end