diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-02-11 17:14:23 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-02-11 17:14:23 -0800 |
commit | 55a4fb5e705671058ffe6d9af965742d560c31e5 (patch) | |
tree | 8481d28befaf113680275648c3629da752153945 | |
parent | a5b61269f3bb08ba270e15c043dc64329f1e10d7 (diff) | |
download | rails-55a4fb5e705671058ffe6d9af965742d560c31e5.tar.gz rails-55a4fb5e705671058ffe6d9af965742d560c31e5.tar.bz2 rails-55a4fb5e705671058ffe6d9af965742d560c31e5.zip |
fixture should quack like a hash
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb | 10 |
1 files changed, 9 insertions, 1 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 7e3f58a411..5c1ce173c8 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb @@ -261,7 +261,15 @@ 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 "INSERT INTO #{quote_table_name(table_name)} (#{fixture.key_list}) VALUES (#{fixture.value_list})", 'Fixture Insert' + columns = Hash[columns(table_name).map { |c| [c.name, c] }] + + key_list = [] + value_list = fixture.map do |name, value| + key_list << quote_column_name(name) + quote(value, columns[name]) + end + + execute "INSERT INTO #{quote_table_name(table_name)} (#{key_list.join(', ')}) VALUES (#{value_list.join(', ')})", 'Fixture Insert' end def empty_insert_statement_value |