diff options
author | Chris Constantine <cconstan@gmail.com> | 2013-04-07 01:44:53 -0700 |
---|---|---|
committer | Chris Constantine <cconstan@gmail.com> | 2013-04-08 09:55:26 -0700 |
commit | f6c4cded2f066db42ef83b30f6c353e2958f81fb (patch) | |
tree | bac27e90fe848f3a01241088c004b3bc79db69be /activerecord/lib/active_record | |
parent | 436d91869b7febc0030d79adea136add2f526e49 (diff) | |
download | rails-f6c4cded2f066db42ef83b30f6c353e2958f81fb.tar.gz rails-f6c4cded2f066db42ef83b30f6c353e2958f81fb.tar.bz2 rails-f6c4cded2f066db42ef83b30f6c353e2958f81fb.zip |
Fix loading of string arrays in postgres
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb b/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb index 9b5170f657..a16e7facce 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb @@ -44,6 +44,21 @@ module ActiveRecord end end + + # Inserts the given fixture into the table. + def insert_fixture(fixture, table_name) + columns = schema_cache.columns_hash(table_name) + + key_list = [] + value_list = fixture.map do |name, value| + key_list << quote_column_name(name) + [columns[name], value] + end + + insert_statement = "INSERT INTO #{quote_table_name(table_name)} (#{key_list.join(", ")}) VALUES (#{key_list.count.times.map{|i| "$#{i+1}" }.join(", ")})" + exec_insert(insert_statement, 'Fixture Insert', value_list) + end + # Executes a SELECT query and returns an array of rows. Each row is an # array of field values. def select_rows(sql, name = nil) |