Class: ActiveRecord::Associations::ClassMethods::JoinDependency
- Inherits:
-
Object
- Object
- ActiveRecord::Associations::ClassMethods::JoinDependency
- Defined in:
- lib/active_record/associations.rb
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.
1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 |
# File 'lib/active_record/associations.rb', line 1226 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.
1224 1225 1226 |
# File 'lib/active_record/associations.rb', line 1224 def joins @joins end |
#reflections ⇒ Object (readonly)
Returns the value of attribute reflections.
1224 1225 1226 |
# File 'lib/active_record/associations.rb', line 1224 def reflections @reflections end |
#table_aliases ⇒ Object (readonly)
Returns the value of attribute table_aliases.
1224 1225 1226 |
# File 'lib/active_record/associations.rb', line 1224 def table_aliases @table_aliases end |
Instance Method Details
#aliased_table_names_for(table_name) ⇒ Object
1256 1257 1258 |
# File 'lib/active_record/associations.rb', line 1256 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
1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 |
# File 'lib/active_record/associations.rb', line 1245 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
1237 1238 1239 |
# File 'lib/active_record/associations.rb', line 1237 def join_associations @joins[1..-1].to_a end |
#join_base ⇒ Object
1241 1242 1243 |
# File 'lib/active_record/associations.rb', line 1241 def join_base @joins[0] end |