Class: ActiveRecord::Associations::ClassMethods::JoinDependency::JoinBase
- Inherits:
-
Object
- Object
- ActiveRecord::Associations::ClassMethods::JoinDependency::JoinBase
- Defined in:
- lib/active_record/associations.rb
Overview
:nodoc:
Direct Known Subclasses
Instance Attribute Summary collapse
-
#active_record ⇒ Object
readonly
Returns the value of attribute active_record.
-
#table_joins ⇒ Object
readonly
Returns the value of attribute table_joins.
Instance Method Summary collapse
- #aliased_prefix ⇒ Object
- #aliased_primary_key ⇒ Object
- #aliased_table_name ⇒ Object
- #column_names_with_alias ⇒ Object
- #extract_record(row) ⇒ Object
-
#initialize(active_record, joins = nil) ⇒ JoinBase
constructor
A new instance of JoinBase.
- #instantiate(row) ⇒ Object
- #record_id(row) ⇒ Object
Constructor Details
#initialize(active_record, joins = nil) ⇒ JoinBase
Returns a new instance of JoinBase.
1411 1412 1413 1414 1415 |
# File 'lib/active_record/associations.rb', line 1411 def initialize(active_record, joins = nil) @active_record = active_record @cached_record = {} @table_joins = joins end |
Instance Attribute Details
#active_record ⇒ Object (readonly)
Returns the value of attribute active_record.
1408 1409 1410 |
# File 'lib/active_record/associations.rb', line 1408 def active_record @active_record end |
#table_joins ⇒ Object (readonly)
Returns the value of attribute table_joins.
1408 1409 1410 |
# File 'lib/active_record/associations.rb', line 1408 def table_joins @table_joins end |
Instance Method Details
#aliased_prefix ⇒ Object
1417 1418 1419 |
# File 'lib/active_record/associations.rb', line 1417 def aliased_prefix "t0" end |
#aliased_primary_key ⇒ Object
1421 1422 1423 |
# File 'lib/active_record/associations.rb', line 1421 def aliased_primary_key "#{ aliased_prefix }_r0" end |
#aliased_table_name ⇒ Object
1425 1426 1427 |
# File 'lib/active_record/associations.rb', line 1425 def aliased_table_name active_record.table_name end |
#column_names_with_alias ⇒ Object
1429 1430 1431 1432 1433 1434 1435 1436 1437 |
# File 'lib/active_record/associations.rb', line 1429 def column_names_with_alias unless @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 return @column_names_with_alias end |
#extract_record(row) ⇒ Object
1439 1440 1441 |
# File 'lib/active_record/associations.rb', line 1439 def extract_record(row) column_names_with_alias.inject({}){|record, (cn, an)| record[cn] = row[an]; record} end |
#instantiate(row) ⇒ Object
1447 1448 1449 |
# File 'lib/active_record/associations.rb', line 1447 def instantiate(row) @cached_record[record_id(row)] ||= active_record.instantiate(extract_record(row)) end |
#record_id(row) ⇒ Object
1443 1444 1445 |
# File 'lib/active_record/associations.rb', line 1443 def record_id(row) row[aliased_primary_key] end |