diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-01-09 14:19:43 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-01-09 14:19:43 -0800 |
commit | 2af5303683f729bb1a4eb582a023276b8a0db402 (patch) | |
tree | cca196e03e151220461a307c6eb559b08fa0f832 | |
parent | b0acc77edced44e47c8570bf7dddd4ce19f06cb0 (diff) | |
parent | da65fe9e11b7f445847228753e6df46d376e29ab (diff) | |
download | rails-2af5303683f729bb1a4eb582a023276b8a0db402.tar.gz rails-2af5303683f729bb1a4eb582a023276b8a0db402.tar.bz2 rails-2af5303683f729bb1a4eb582a023276b8a0db402.zip |
Merge branch 'master' into ruby-2.2
* master:
Revert "ask the fixture set for the sql statements"
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb | 6 | ||||
-rw-r--r-- | activerecord/lib/active_record/fixtures.rb | 22 |
2 files changed, 11 insertions, 17 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb index e196df079b..c90915c509 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb @@ -286,10 +286,6 @@ module ActiveRecord # Inserts the given fixture into the table. Overridden in adapters that require # something beyond a simple insert (eg. Oracle). def insert_fixture(fixture, table_name) - execute fixture_sql(fixture, table_name), 'Fixture Insert' - end - - def fixture_sql(fixture, table_name) columns = schema_cache.columns_hash(table_name) key_list = [] @@ -298,7 +294,7 @@ module ActiveRecord quote(value, columns[name]) end - "INSERT INTO #{quote_table_name(table_name)} (#{key_list.join(', ')}) VALUES (#{value_list.join(', ')})" + execute "INSERT INTO #{quote_table_name(table_name)} (#{key_list.join(', ')}) VALUES (#{value_list.join(', ')})", 'Fixture Insert' end def empty_insert_statement_value diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb index a7a54483bc..fee3f51d9e 100644 --- a/activerecord/lib/active_record/fixtures.rb +++ b/activerecord/lib/active_record/fixtures.rb @@ -521,8 +521,16 @@ module ActiveRecord connection.transaction(:requires_new => true) do fixture_sets.each do |fs| conn = fs.model_class.respond_to?(:connection) ? fs.model_class.connection : connection - fs.fixture_sql(conn).each do |stmt| - conn.execute stmt + table_rows = fs.table_rows + + table_rows.keys.each do |table| + conn.delete "DELETE FROM #{conn.quote_table_name(table)}", 'Fixture Delete' + end + + table_rows.each do |fixture_set_name, rows| + rows.each do |row| + conn.insert_fixture(row, fixture_set_name) + end end end @@ -594,16 +602,6 @@ module ActiveRecord fixtures.size end - def fixture_sql(conn) - table_rows = self.table_rows - - table_rows.keys.map { |table| - "DELETE FROM #{conn.quote_table_name(table)}" - }.concat table_rows.flat_map { |fixture_set_name, rows| - rows.map { |row| conn.fixture_sql(row, fixture_set_name) } - } - end - # Returns a hash of rows to be inserted. The key is the table, the value is # a list of rows to insert to that table. def table_rows |