Class: ActiveRecord::Associations::ClassMethods::JoinDependency
- Inherits:
-
Object
- Object
- ActiveRecord::Associations::ClassMethods::JoinDependency
- Defined in:
- lib/active_record/associations.rb
Overview
:nodoc:
Defined Under Namespace
Classes: JoinAssociation, JoinBase
Instance Attribute Summary collapse
-
#joins ⇒ Object
readonly
Returns the value of attribute joins.
-
#reflections ⇒ Object
readonly
Returns the value of attribute reflections.
-
#table_aliases ⇒ Object
readonly
Returns the value of attribute table_aliases.
Instance Method Summary collapse
- #aliased_table_names_for(table_name) ⇒ Object
-
#initialize(base, associations, joins) ⇒ JoinDependency
constructor
A new instance of JoinDependency.
- #instantiate(rows) ⇒ Object
- #join_associations ⇒ Object
- #join_base ⇒ Object
Constructor Details
#initialize(base, associations, joins) ⇒ JoinDependency
Returns a new instance of JoinDependency.
1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 |
# File 'lib/active_record/associations.rb', line 1306 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
#joins ⇒ Object (readonly)
Returns the value of attribute joins.
1304 1305 1306 |
# File 'lib/active_record/associations.rb', line 1304 def joins @joins end |
#reflections ⇒ Object (readonly)
Returns the value of attribute reflections.
1304 1305 1306 |
# File 'lib/active_record/associations.rb', line 1304 def reflections @reflections end |
#table_aliases ⇒ Object (readonly)
Returns the value of attribute table_aliases.
1304 1305 1306 |
# File 'lib/active_record/associations.rb', line 1304 def table_aliases @table_aliases end |
Instance Method Details
#aliased_table_names_for(table_name) ⇒ Object
1336 1337 1338 |
# File 'lib/active_record/associations.rb', line 1336 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
1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 |
# File 'lib/active_record/associations.rb', line 1325 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_associations ⇒ Object
1317 1318 1319 |
# File 'lib/active_record/associations.rb', line 1317 def join_associations @joins[1..-1].to_a end |
#join_base ⇒ Object
1321 1322 1323 |
# File 'lib/active_record/associations.rb', line 1321 def join_base @joins[0] end |