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.



1968
1969
1970
1971
1972
# File 'lib/active_record/associations.rb', line 1968

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.



1965
1966
1967
# File 'lib/active_record/associations.rb', line 1965

def active_record
  @active_record
end

#table_joinsObject (readonly)

Returns the value of attribute table_joins.



1965
1966
1967
# File 'lib/active_record/associations.rb', line 1965

def table_joins
  @table_joins
end

Instance Method Details

#aliased_prefixObject



1974
1975
1976
# File 'lib/active_record/associations.rb', line 1974

def aliased_prefix
  "t0"
end

#aliased_primary_keyObject



1978
1979
1980
# File 'lib/active_record/associations.rb', line 1978

def aliased_primary_key
  "#{aliased_prefix}_r0"
end

#aliased_table_nameObject



1982
1983
1984
# File 'lib/active_record/associations.rb', line 1982

def aliased_table_name
  active_record.table_name
end

#column_names_with_aliasObject



1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
# File 'lib/active_record/associations.rb', line 1986

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



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

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

#instantiate(row) ⇒ Object



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

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

#record_id(row) ⇒ Object



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

def record_id(row)
  row[aliased_primary_key]
end