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

- (JoinBase) initialize(active_record, joins = nil)



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

- (Object) active_record (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

- (Object) table_joins (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

- (Object) ==(other)



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

- (Object) aliased_prefix



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

def aliased_prefix
  "t0"
end

- (Object) aliased_primary_key



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

def aliased_primary_key
  "#{aliased_prefix}_r0"
end

- (Object) aliased_table_name



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

def aliased_table_name
  active_record.table_name
end

- (Object) column_names_with_alias



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

- (Object) extract_record(row)



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

- (Object) instantiate(row)



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

- (Object) record_id(row)



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

def record_id(row)
  row[aliased_primary_key]
end