class ActiveRecord::Associations::JoinDependency::JoinPart
:nodoc:
two; one for the join table and one for the target table).
operations (for example a has_and_belongs_to_many JoinAssociation would result in
is joining to the base. A JoinAssociation may result in more than one actual join
everything else is being joined onto. A JoinAssociation represents an association which
by JoinBase and JoinAssociation. A JoinBase represents the Active Record which
A JoinPart represents a part of a JoinDependency. It is inherited
:nodoc:
def ==(other)
def ==(other) raise NotImplementedError end
def aliased_prefix
def aliased_prefix raise NotImplementedError end
def aliased_primary_key
def aliased_primary_key "#{aliased_prefix}_r0" end
def aliased_table
def aliased_table Arel::Nodes::TableAlias.new table, aliased_table_name end
def aliased_table_name
def aliased_table_name raise NotImplementedError end
def column_names_with_alias
def column_names_with_alias unless @column_names_with_alias @column_names_with_alias = [] ([primary_key] + (column_names - [primary_key])).compact.each_with_index do |column_name, i| @column_names_with_alias << [column_name, "#{aliased_prefix}_r#{i}"] end end @column_names_with_alias end
def extract_record(row)
def extract_record(row) # 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_name, alias_name = column_names_with_alias[index] hash[column_name] = row[alias_name] index += 1 end hash end
def initialize(base_klass)
def initialize(base_klass) @base_klass = base_klass @cached_record = {} @column_names_with_alias = nil end
def instantiate(row)
def instantiate(row) @cached_record[record_id(row)] ||= base_klass.instantiate(extract_record(row)) end
def record_id(row)
def record_id(row) row[aliased_primary_key] end
def table
def table raise NotImplementedError end