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.



1992
1993
1994
1995
1996
# File 'lib/active_record/associations.rb', line 1992

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.



1989
1990
1991
# File 'lib/active_record/associations.rb', line 1989

def active_record
  @active_record
end

#table_joinsObject (readonly)

Returns the value of attribute table_joins.



1989
1990
1991
# File 'lib/active_record/associations.rb', line 1989

def table_joins
  @table_joins
end

Instance Method Details

#aliased_prefixObject



1998
1999
2000
# File 'lib/active_record/associations.rb', line 1998

def aliased_prefix
  "t0"
end

#aliased_primary_keyObject



2002
2003
2004
# File 'lib/active_record/associations.rb', line 2002

def aliased_primary_key
  "#{aliased_prefix}_r0"
end

#aliased_table_nameObject



2006
2007
2008
# File 'lib/active_record/associations.rb', line 2006

def aliased_table_name
  active_record.table_name
end

#column_names_with_aliasObject



2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
# File 'lib/active_record/associations.rb', line 2010

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



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

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

#instantiate(row) ⇒ Object



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

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

#record_id(row) ⇒ Object



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

def record_id(row)
  row[aliased_primary_key]
end