From 67e46e42549f1dac435041d68c05717d0a0f54b6 Mon Sep 17 00:00:00 2001 From: Montana Low Date: Fri, 30 Jan 2015 13:56:37 -0800 Subject: Use the correct connection for reset_pk_sequence When a fs.model_class.connection uses a different database than connection, connection.reset_pk_sequence will fail with an exception causing fixture load to rollback. This is reproducible for any ActiveRecord::Base class that calls establish_connection with a different database. --- activerecord/lib/active_record/fixtures.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'activerecord/lib/active_record/fixtures.rb') diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb index 739be524da..1bfdfb6608 100644 --- a/activerecord/lib/active_record/fixtures.rb +++ b/activerecord/lib/active_record/fixtures.rb @@ -539,12 +539,10 @@ module ActiveRecord conn.insert_fixture(row, fixture_set_name) end end - end - # Cap primary key sequences to max(pk). - if connection.respond_to?(:reset_pk_sequence!) - fixture_sets.each do |fs| - connection.reset_pk_sequence!(fs.table_name) + # Cap primary key sequences to max(pk). + if conn.respond_to?(:reset_pk_sequence!) + conn.reset_pk_sequence!(fs.table_name) end end end -- cgit v1.2.3