1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Pass connection rather than alias_tracker

Because we're only using the `connection` so passing the entire tracker
isn't unnecessary.

Eventually only the `connection` will be passed to `add_constraints`
with later refactoring but curretly that's not possible because of
`construct_tables` method.
This commit is contained in:
eileencodes 2014-12-09 13:56:52 -05:00
parent 9688270d3e
commit 80099618e4

View file

@ -10,8 +10,8 @@ module ActiveRecord
@block = block
end
def bind_value(scope, column, value, alias_tracker)
substitute = alias_tracker.connection.substitute_at(column)
def bind_value(scope, column, value, connection)
substitute = connection.substitute_at(column)
scope.bind_values += [[column, @block.call(value)]]
substitute
end
@ -81,38 +81,38 @@ module ActiveRecord
table.create_join(table, table.create_on(constraint), join_type)
end
def column_for(table_name, column_name, alias_tracker)
columns = alias_tracker.connection.schema_cache.columns_hash(table_name)
def column_for(table_name, column_name, connection)
columns = connection.schema_cache.columns_hash(table_name)
columns[column_name]
end
def bind_value(scope, column, value, alias_tracker)
@bind_substitution.bind_value scope, column, value, alias_tracker
def bind_value(scope, column, value, connection)
@bind_substitution.bind_value scope, column, value, connection
end
def bind(scope, table_name, column_name, value, tracker)
column = column_for table_name, column_name, tracker
bind_value scope, column, value, tracker
def bind(scope, table_name, column_name, value, connection)
column = column_for table_name, column_name, connection
bind_value scope, column, value, connection
end
def last_chain_scope(scope, table, reflection, owner, tracker, assoc_klass)
def last_chain_scope(scope, table, reflection, owner, connection, assoc_klass)
join_keys = reflection.join_keys(assoc_klass)
key = join_keys.key
foreign_key = join_keys.foreign_key
bind_val = bind scope, table.table_name, key.to_s, owner[foreign_key], tracker
bind_val = bind scope, table.table_name, key.to_s, owner[foreign_key], connection
scope = scope.where(table[key].eq(bind_val))
if reflection.type
value = owner.class.base_class.name
bind_val = bind scope, table.table_name, reflection.type, value, tracker
bind_val = bind scope, table.table_name, reflection.type, value, connection
scope = scope.where(table[reflection.type].eq(bind_val))
else
scope
end
end
def next_chain_scope(scope, table, reflection, tracker, assoc_klass, foreign_table, next_reflection)
def next_chain_scope(scope, table, reflection, connection, assoc_klass, foreign_table, next_reflection)
join_keys = reflection.join_keys(assoc_klass)
key = join_keys.key
foreign_key = join_keys.foreign_key
@ -121,7 +121,7 @@ module ActiveRecord
if reflection.type
value = next_reflection.klass.base_class.name
bind_val = bind scope, table.table_name, reflection.type, value, tracker
bind_val = bind scope, table.table_name, reflection.type, value, connection
scope = scope.where(table[reflection.type].eq(bind_val))
end
@ -131,19 +131,20 @@ module ActiveRecord
def add_constraints(scope, owner, assoc_klass, refl, tracker)
chain = refl.chain
scope_chain = refl.scope_chain
connection = tracker.connection
tables = construct_tables(chain, assoc_klass, refl, tracker)
owner_reflection = chain.last
table = tables.last
scope = last_chain_scope(scope, table, owner_reflection, owner, tracker, assoc_klass)
scope = last_chain_scope(scope, table, owner_reflection, owner, connection, assoc_klass)
chain.each_with_index do |reflection, i|
table, foreign_table = tables.shift, tables.first
unless reflection == chain.last
next_reflection = chain[i + 1]
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
is_first_chain = i == 0