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

Inherits:
Object
  • Object
show all
Defined in:
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

Returns a new instance of JoinBase.



2046
2047
2048
2049
2050
# File 'lib/active_record/associations.rb', line 2046

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.



2043
2044
2045
# File 'lib/active_record/associations.rb', line 2043

def active_record
  @active_record
end

#table_joinsObject (readonly)

Returns the value of attribute table_joins.



2043
2044
2045
# File 'lib/active_record/associations.rb', line 2043

def table_joins
  @table_joins
end

Instance Method Details

#==(other) ⇒ Object



2052
2053
2054
2055
# File 'lib/active_record/associations.rb', line 2052

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

#aliased_prefixObject



2057
2058
2059
# File 'lib/active_record/associations.rb', line 2057

def aliased_prefix
  "t0"
end

#aliased_primary_keyObject



2061
2062
2063
# File 'lib/active_record/associations.rb', line 2061

def aliased_primary_key
  "#{aliased_prefix}_r0"
end

#aliased_table_nameObject



2065
2066
2067
# File 'lib/active_record/associations.rb', line 2065

def aliased_table_name
  active_record.table_name
end

#column_names_with_aliasObject



2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
# File 'lib/active_record/associations.rb', line 2069

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



2081
2082
2083
# File 'lib/active_record/associations.rb', line 2081

def extract_record(row)
  Hash[column_names_with_alias.map{|cn, an| [cn, row[an]]}]
end

#instantiate(row) ⇒ Object



2089
2090
2091
# File 'lib/active_record/associations.rb', line 2089

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

#record_id(row) ⇒ Object



2085
2086
2087
# File 'lib/active_record/associations.rb', line 2085

def record_id(row)
  row[aliased_primary_key]
end