Pass connection rather than alias_tracker

After the refactorings we're only using the connection and not the alias
tracker anymore. This builds on commit 18019.

Reuse the already available `@connection` to reduce the surface area of
the alias tracker's API. We can then remove the `attr_reader` because
the connection is already available.
This commit is contained in:
eileencodes 2014-12-09 13:56:52 -05:00
parent f6729309a0
commit cc9b813a82
2 changed files with 7 additions and 7 deletions

@ -5,7 +5,7 @@ module Associations
# Keeps track of table aliases for ActiveRecord::Associations::ClassMethods::JoinDependency and
# ActiveRecord::Associations::ThroughAssociationScope
class AliasTracker # :nodoc:
attr_reader :aliases, :connection
attr_reader :aliases
def self.empty(connection)
new connection, Hash.new(0)
@ -63,7 +63,7 @@ def aliased_table_for(table_name, aliased_name, **table_options)
Arel::Table.new(table_name, table_options)
else
# Otherwise, we need to use an alias
aliased_name = connection.table_alias_for(aliased_name)
aliased_name = @connection.table_alias_for(aliased_name)
# Update the count
aliases[aliased_name] += 1
@ -80,7 +80,7 @@ def aliased_table_for(table_name, aliased_name, **table_options)
private
def truncate(name)
name.slice(0, connection.table_alias_length - 2)
name.slice(0, @connection.table_alias_length - 2)
end
end
end

@ -37,7 +37,7 @@ def scope(association, connection)
chain_head, chain_tail = get_chain(reflection, association, alias_tracker)
scope.extending! Array(reflection.options[:extend])
add_constraints(scope, owner, klass, reflection, alias_tracker, chain_head, chain_tail)
add_constraints(scope, owner, klass, reflection, connection, chain_head, chain_tail)
end
def join_type
@ -139,10 +139,10 @@ def get_chain(refl, association, tracker)
[runtime_reflection, prev]
end
def add_constraints(scope, owner, assoc_klass, refl, tracker, chain_head, chain_tail)
def add_constraints(scope, owner, assoc_klass, refl, connection, chain_head, chain_tail)
owner_reflection = chain_tail
table = owner_reflection.alias_name
scope = last_chain_scope(scope, table, owner_reflection, owner, tracker, assoc_klass)
scope = last_chain_scope(scope, table, owner_reflection, owner, connection, assoc_klass)
reflection = chain_head
loop do
@ -152,7 +152,7 @@ def add_constraints(scope, owner, assoc_klass, refl, tracker, chain_head, chain_
unless reflection == chain_tail
next_reflection = reflection.next
foreign_table = next_reflection.alias_name
scope = next_chain_scope(scope, table, reflection, tracker, assoc_klass, foreign_table, next_reflection)
scope = next_chain_scope(scope, table, reflection, connection, assoc_klass, foreign_table, next_reflection)
end
# Exclude the scope of the association itself, because that