aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activerecord/lib/active_record/associations/alias_tracker.rb19
-rw-r--r--activerecord/lib/active_record/associations/association_scope.rb1
-rw-r--r--activerecord/lib/active_record/associations/join_dependency.rb3
3 files changed, 12 insertions, 11 deletions
diff --git a/activerecord/lib/active_record/associations/alias_tracker.rb b/activerecord/lib/active_record/associations/alias_tracker.rb
index 27d918696a..36e62fe6b1 100644
--- a/activerecord/lib/active_record/associations/alias_tracker.rb
+++ b/activerecord/lib/active_record/associations/alias_tracker.rb
@@ -7,18 +7,21 @@ module ActiveRecord
class AliasTracker # :nodoc:
attr_reader :aliases
- def self.empty(connection)
- new connection, Hash.new(0)
+ def self.create(connection, initial_table)
+ aliases = Hash.new(0)
+ aliases[initial_table] = 1
+ new connection, aliases
end
- def self.create(connection, table_joins)
- if table_joins.empty?
- empty connection
+ def self.create_with_joins(connection, initial_table, joins, type_caster)
+ if joins.empty?
+ create(connection, initial_table, type_caster)
else
- aliases = Hash.new { |h,k|
- h[k] = initial_count_for(connection, k, table_joins)
+ aliases = Hash.new { |h, k|
+ h[k] = initial_count_for(connection, k, joins)
}
- new connection, aliases
+ aliases[initial_table] = 1
+ new connection, aliases, type_caster
end
end
diff --git a/activerecord/lib/active_record/associations/association_scope.rb b/activerecord/lib/active_record/associations/association_scope.rb
index 9d94822fc5..1f77a083aa 100644
--- a/activerecord/lib/active_record/associations/association_scope.rb
+++ b/activerecord/lib/active_record/associations/association_scope.rb
@@ -126,7 +126,6 @@ module ActiveRecord
def get_chain(refl, association, tracker)
name = refl.name
runtime_reflection = ActiveRecord::Reflection::RuntimeReflection.new(refl, association)
- alias_name = tracker.aliased_table_for(runtime_reflection.table_name, runtime_reflection.alias_candidate(name))
prev = runtime_reflection
refl.chain.drop(1).each { |reflection|
alias_name = tracker.aliased_table_for(reflection.table_name, reflection.alias_candidate(name))
diff --git a/activerecord/lib/active_record/associations/join_dependency.rb b/activerecord/lib/active_record/associations/join_dependency.rb
index 66e997c3c8..634abfac96 100644
--- a/activerecord/lib/active_record/associations/join_dependency.rb
+++ b/activerecord/lib/active_record/associations/join_dependency.rb
@@ -93,8 +93,7 @@ module ActiveRecord
# joins # => []
#
def initialize(base, associations, joins)
- @alias_tracker = AliasTracker.create(base.connection, joins)
- @alias_tracker.aliased_table_for(base.table_name, base.table_name, type_caster: base.type_caster) # Updates the count for base.table_name to 1
+ @alias_tracker = AliasTracker.create_with_joins(base.connection, base.table_name, joins)
tree = self.class.make_tree associations
@join_root = JoinBase.new base, build(tree, base)
@join_root.children.each { |child| construct_tables! @join_root, child }