diff options
author | Kir Shatrov <shatrov@me.com> | 2017-06-16 21:27:20 -0400 |
---|---|---|
committer | Kir Shatrov <shatrov@me.com> | 2017-06-19 16:05:17 -0400 |
commit | 67ad6bb3be4d9a1b335cffee351e9750aa572aab (patch) | |
tree | 0d26a4d40ab053838f15665268e98d9a148dd46f | |
parent | e57d8d090d5d6860e3a5bb3257d6aed5b644ea25 (diff) | |
download | rails-67ad6bb3be4d9a1b335cffee351e9750aa572aab.tar.gz rails-67ad6bb3be4d9a1b335cffee351e9750aa572aab.tar.bz2 rails-67ad6bb3be4d9a1b335cffee351e9750aa572aab.zip |
Refactor #insert_fixtures to use Arel
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb | 15 |
1 files changed, 11 insertions, 4 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 c6811a4802..56f0d6d1f4 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb @@ -308,16 +308,23 @@ module ActiveRecord raise Fixture::FixtureError, %(table "#{table_name}" has no column named #{name.inspect}.) end end - key_list = fixture.keys.map { |name| quote_column_name(name) } - value_list = binds.map(&:value_for_database).map do |value| + + table = Arel::Table.new(table_name) + + values = binds.map do |bind| + value = bind.value_for_database begin quote(value) rescue TypeError - quote(YAML.dump(value)) + value = YAML.dump(value) end + [table[bind.name], value] end - execute "INSERT INTO #{quote_table_name(table_name)} (#{key_list.join(', ')}) VALUES (#{value_list.join(', ')})", "Fixture Insert" + manager = Arel::InsertManager.new + manager.into(table) + manager.insert(values) + execute manager.to_sql, "Fixture Insert" end def empty_insert_statement_value |