Class: ActiveRecord::Associations::ClassMethods::JoinDependency::JoinPart
- Inherits:
-
Object
- Object
- ActiveRecord::Associations::ClassMethods::JoinDependency::JoinPart
- Defined in:
- activerecord/lib/active_record/associations/class_methods/join_dependency/join_part.rb
Overview
A JoinPart represents a part of a JoinDependency. It is an abstract class, inherited by JoinBase and JoinAssociation. A JoinBase represents the Active Record which everything else is being joined onto. A JoinAssociation represents an association which is joining to the base. A JoinAssociation may result in more than one actual join operations (for example a has_and_belongs_to_many JoinAssociation would result in two; one for the join table and one for the target table).
Instance Attribute Summary (collapse)
-
- (Object) active_record
readonly
The Active Record class which this join part is associated 'about'; for a JoinBase this is the actual base model, for a JoinAssociation this is the target model of the association.
Instance Method Summary (collapse)
- - (Object) ==(other)
-
- (Object) aliased_prefix
The prefix to be used when aliasing columns in the active_record's table.
-
- (Object) aliased_primary_key
The alias for the primary key of the active_record's table.
- - (Object) aliased_table
-
- (Object) aliased_table_name
The alias for the active_record's table.
-
- (Object) column_names_with_alias
An array of [column_name, alias] pairs for the table.
- - (Object) extract_record(row)
-
- (JoinPart) initialize(active_record)
constructor
A new instance of JoinPart.
- - (Object) instantiate(row)
- - (Object) record_id(row)
-
- (Object) table
An Arel::Table for the active_record.
Constructor Details
- (JoinPart) initialize(active_record)
A new instance of JoinPart
19 20 21 22 23 |
# File 'activerecord/lib/active_record/associations/class_methods/join_dependency/join_part.rb', line 19 def initialize(active_record) @active_record = active_record @cached_record = {} @column_names_with_alias = nil end |
Instance Attribute Details
- (Object) active_record (readonly)
The Active Record class which this join part is associated 'about'; for a JoinBase this is the actual base model, for a JoinAssociation this is the target model of the association.
15 16 17 |
# File 'activerecord/lib/active_record/associations/class_methods/join_dependency/join_part.rb', line 15 def active_record @active_record end |
Instance Method Details
- (Object) ==(other)
29 30 31 |
# File 'activerecord/lib/active_record/associations/class_methods/join_dependency/join_part.rb', line 29 def ==(other) raise NotImplementedError end |
- (Object) aliased_prefix
The prefix to be used when aliasing columns in the active_record's table
39 40 41 |
# File 'activerecord/lib/active_record/associations/class_methods/join_dependency/join_part.rb', line 39 def aliased_prefix raise NotImplementedError end |
- (Object) aliased_primary_key
The alias for the primary key of the active_record's table
49 50 51 |
# File 'activerecord/lib/active_record/associations/class_methods/join_dependency/join_part.rb', line 49 def aliased_primary_key "#{aliased_prefix}_r0" end |
- (Object) aliased_table
25 26 27 |
# File 'activerecord/lib/active_record/associations/class_methods/join_dependency/join_part.rb', line 25 def aliased_table Arel::Nodes::TableAlias.new aliased_table_name, table end |
- (Object) aliased_table_name
The alias for the active_record's table
44 45 46 |
# File 'activerecord/lib/active_record/associations/class_methods/join_dependency/join_part.rb', line 44 def aliased_table_name raise NotImplementedError end |
- (Object) column_names_with_alias
An array of [column_name, alias] pairs for the table
54 55 56 57 58 59 60 61 62 63 |
# File 'activerecord/lib/active_record/associations/class_methods/join_dependency/join_part.rb', line 54 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 @column_names_with_alias end |
- (Object) extract_record(row)
65 66 67 |
# File 'activerecord/lib/active_record/associations/class_methods/join_dependency/join_part.rb', line 65 def extract_record(row) Hash[column_names_with_alias.map{|cn, an| [cn, row[an]]}] end |
- (Object) instantiate(row)
73 74 75 |
# File 'activerecord/lib/active_record/associations/class_methods/join_dependency/join_part.rb', line 73 def instantiate(row) @cached_record[record_id(row)] ||= active_record.send(:instantiate, extract_record(row)) end |
- (Object) record_id(row)
69 70 71 |
# File 'activerecord/lib/active_record/associations/class_methods/join_dependency/join_part.rb', line 69 def record_id(row) row[aliased_primary_key] end |
- (Object) table
An Arel::Table for the active_record
34 35 36 |
# File 'activerecord/lib/active_record/associations/class_methods/join_dependency/join_part.rb', line 34 def table raise NotImplementedError end |