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

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

Defined Under Namespace

Classes: JoinAssociation, JoinBase

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base, associations, joins) ⇒ JoinDependency

Returns a new instance of JoinDependency.



1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
# File 'lib/active_record/associations.rb', line 1245

def initialize(base, associations, joins)
  @joins                 = [JoinBase.new(base, joins)]
  @associations          = associations
  @reflections           = []
  @base_records_hash     = {}
  @base_records_in_order = []
  @table_aliases         = Hash.new { |aliases, table| aliases[table] = 0 }
  @table_aliases[base.table_name] = 1
  build(associations)
end

Instance Attribute Details

#joinsObject (readonly)

Returns the value of attribute joins.



1243
1244
1245
# File 'lib/active_record/associations.rb', line 1243

def joins
  @joins
end

#reflectionsObject (readonly)

Returns the value of attribute reflections.



1243
1244
1245
# File 'lib/active_record/associations.rb', line 1243

def reflections
  @reflections
end

#table_aliasesObject (readonly)

Returns the value of attribute table_aliases.



1243
1244
1245
# File 'lib/active_record/associations.rb', line 1243

def table_aliases
  @table_aliases
end

Instance Method Details

#aliased_table_names_for(table_name) ⇒ Object



1275
1276
1277
# File 'lib/active_record/associations.rb', line 1275

def aliased_table_names_for(table_name)
  joins.select{|join| join.table_name == table_name }.collect{|join| join.aliased_table_name}
end

#instantiate(rows) ⇒ Object



1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
# File 'lib/active_record/associations.rb', line 1264

def instantiate(rows)
  rows.each_with_index do |row, i|
    primary_id = join_base.record_id(row)
    unless @base_records_hash[primary_id]
      @base_records_in_order << (@base_records_hash[primary_id] = join_base.instantiate(row))
    end
    construct(@base_records_hash[primary_id], @associations, join_associations.dup, row)
  end
  return @base_records_in_order
end

#join_associationsObject



1256
1257
1258
# File 'lib/active_record/associations.rb', line 1256

def join_associations
  @joins[1..-1].to_a
end

#join_baseObject



1260
1261
1262
# File 'lib/active_record/associations.rb', line 1260

def join_base
  @joins[0]
end