Class: ActiveRecord::Associations::ClassMethods::JoinDependency::JoinBase

Inherits:
Object
  • Object
show all
Defined in:
activerecord/lib/active_record/associations.rb

Overview

:nodoc:

Direct Known Subclasses

JoinAssociation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(active_record, joins = nil) ⇒ JoinBase



2015
2016
2017
2018
2019
# File 'activerecord/lib/active_record/associations.rb', line 2015

def initialize(active_record, joins = nil)
  @active_record = active_record
  @cached_record = {}
  @table_joins   = joins
end

Instance Attribute Details

#active_recordObject (readonly)

Returns the value of attribute active_record



2012
2013
2014
# File 'activerecord/lib/active_record/associations.rb', line 2012

def active_record
  @active_record
end

#table_joinsObject (readonly)

Returns the value of attribute table_joins



2012
2013
2014
# File 'activerecord/lib/active_record/associations.rb', line 2012

def table_joins
  @table_joins
end

Instance Method Details

#==(other) ⇒ Object



2021
2022
2023
2024
2025
# File 'activerecord/lib/active_record/associations.rb', line 2021

def ==(other)
  other.class == self.class &&
  other.active_record == active_record &&
  other.table_joins == table_joins
end

#aliased_prefixObject



2027
2028
2029
# File 'activerecord/lib/active_record/associations.rb', line 2027

def aliased_prefix
  "t0"
end

#aliased_primary_keyObject



2031
2032
2033
# File 'activerecord/lib/active_record/associations.rb', line 2031

def aliased_primary_key
  "#{aliased_prefix}_r0"
end

#aliased_table_nameObject



2035
2036
2037
# File 'activerecord/lib/active_record/associations.rb', line 2035

def aliased_table_name
  active_record.table_name
end

#column_names_with_aliasObject



2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
# File 'activerecord/lib/active_record/associations.rb', line 2039

def column_names_with_alias
  unless defined?(@column_names_with_alias)
    @column_names_with_alias = []

    ([primary_key] + (column_names - [primary_key])).each_with_index do |column_name, i|
      @column_names_with_alias << [column_name, "#{aliased_prefix}_r#{i}"]
    end
  end

  @column_names_with_alias
end

#extract_record(row) ⇒ Object



2051
2052
2053
# File 'activerecord/lib/active_record/associations.rb', line 2051

def extract_record(row)
  column_names_with_alias.inject({}){|record, (cn, an)| record[cn] = row[an]; record}
end

#instantiate(row) ⇒ Object



2059
2060
2061
# File 'activerecord/lib/active_record/associations.rb', line 2059

def instantiate(row)
  @cached_record[record_id(row)] ||= active_record.send(:instantiate, extract_record(row))
end

#record_id(row) ⇒ Object



2055
2056
2057
# File 'activerecord/lib/active_record/associations.rb', line 2055

def record_id(row)
  row[aliased_primary_key]
end