aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/join_dependency/join_part.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/associations/join_dependency/join_part.rb')
-rw-r--r--activerecord/lib/active_record/associations/join_dependency/join_part.rb46
1 files changed, 5 insertions, 41 deletions
diff --git a/activerecord/lib/active_record/associations/join_dependency/join_part.rb b/activerecord/lib/active_record/associations/join_dependency/join_part.rb
index e6da4d3c9e..91e1c6a9d7 100644
--- a/activerecord/lib/active_record/associations/join_dependency/join_part.rb
+++ b/activerecord/lib/active_record/associations/join_dependency/join_part.rb
@@ -10,10 +10,6 @@ module ActiveRecord
class JoinPart # :nodoc:
include Enumerable
- # A JoinBase instance representing the active record we are joining onto.
- # (So in Author.has_many :posts, the Author would be that base record.)
- attr_reader :parent
-
# 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.
@@ -21,12 +17,10 @@ module ActiveRecord
delegate :table_name, :column_names, :primary_key, :to => :base_klass
- def initialize(base_klass, parent)
+ def initialize(base_klass, children)
@base_klass = base_klass
- @parent = parent
- @cached_record = {}
@column_names_with_alias = nil
- @children = []
+ @children = children
end
def name
@@ -42,43 +36,17 @@ module ActiveRecord
children.each { |child| child.each(&block) }
end
- def aliased_table
- Arel::Nodes::TableAlias.new table, aliased_table_name
- end
-
# An Arel::Table for the active_record
def table
raise NotImplementedError
end
- # The prefix to be used when aliasing columns in the active_record's table
- def aliased_prefix
- raise NotImplementedError
- end
-
# The alias for the active_record's table
def aliased_table_name
raise NotImplementedError
end
- # The alias for the primary key of the active_record's table
- def aliased_primary_key
- "#{aliased_prefix}_r0"
- end
-
- # An array of [column_name, alias] pairs for the table
- def column_names_with_alias
- unless @column_names_with_alias
- @column_names_with_alias = []
-
- column_names.each_with_index do |column_name, i|
- @column_names_with_alias << [column_name, "#{aliased_prefix}_r#{i}"]
- end
- end
- @column_names_with_alias
- end
-
- def extract_record(row)
+ def extract_record(row, column_names_with_alias)
# This code is performance critical as it is called per row.
# see: https://github.com/rails/rails/pull/12185
hash = {}
@@ -95,12 +63,8 @@ module ActiveRecord
hash
end
- def record_id(row)
- row[aliased_primary_key]
- end
-
- def instantiate(row)
- @cached_record[record_id(row)] ||= base_klass.instantiate(extract_record(row))
+ def instantiate(row, aliases)
+ base_klass.instantiate(extract_record(row, aliases))
end
end
end