diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2017-06-19 17:05:18 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-19 17:05:18 -0400 |
commit | 5cf76ccc8dc79d82595ff604b745fed78563b114 (patch) | |
tree | 2195630b6a9cd90d23ed5e97f3fafbdede2bfb83 /activerecord/lib | |
parent | c6d19fc85189b86c0b1422fa13b8f5182b4fd4d0 (diff) | |
parent | 67ad6bb3be4d9a1b335cffee351e9750aa572aab (diff) | |
download | rails-5cf76ccc8dc79d82595ff604b745fed78563b114.tar.gz rails-5cf76ccc8dc79d82595ff604b745fed78563b114.tar.bz2 rails-5cf76ccc8dc79d82595ff604b745fed78563b114.zip |
Merge pull request #29486 from kirs/fixtures-arel
Refactor #insert_fixtures to use Arel
Diffstat (limited to 'activerecord/lib')
-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 |