diff options
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/association_scope.rb | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/activerecord/lib/active_record/associations/association_scope.rb b/activerecord/lib/active_record/associations/association_scope.rb index dcbd57e61d..0ac10531e5 100644 --- a/activerecord/lib/active_record/associations/association_scope.rb +++ b/activerecord/lib/active_record/associations/association_scope.rb @@ -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 |