diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-12-19 21:19:09 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-12-20 14:04:50 -0600 |
commit | 135b3a0dde2edd013b666ab54d35b8b99220f0aa (patch) | |
tree | f6f335500089349ddb213076e645de0170331ccf | |
parent | 776af48acb1035e70a326609ec5e5b632ef0c2c5 (diff) | |
download | rails-135b3a0dde2edd013b666ab54d35b8b99220f0aa.tar.gz rails-135b3a0dde2edd013b666ab54d35b8b99220f0aa.tar.bz2 rails-135b3a0dde2edd013b666ab54d35b8b99220f0aa.zip |
multiple key / values work
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb | 5 | ||||
-rw-r--r-- | activerecord/test/cases/adapters/postgresql/hstore_test.rb | 6 |
2 files changed, 10 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 563f98dc5e..c26b61443b 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -51,7 +51,10 @@ module ActiveRecord end def cast_hstore(string) - Hash[[string.split('=>').map { |k| k[1...-1] }]] + kvs = string.split(', ').map { |kv| + kv.split('=>').map { |k| k[1...-1] } + } + Hash[kvs] end end # :startdoc: diff --git a/activerecord/test/cases/adapters/postgresql/hstore_test.rb b/activerecord/test/cases/adapters/postgresql/hstore_test.rb index aa3bde09d8..5031486f29 100644 --- a/activerecord/test/cases/adapters/postgresql/hstore_test.rb +++ b/activerecord/test/cases/adapters/postgresql/hstore_test.rb @@ -37,4 +37,10 @@ class PostgresqlHstoreTest < ActiveRecord::TestCase x = Hstore.find :first assert_equal({'1' => '2'}, x.tags) end + + def test_select_multikey + @connection.execute "insert into hstores (tags) VALUES ('1=>2,2=>3')" + x = Hstore.find :first + assert_equal({'1' => '2', '2' => '3'}, x.tags) + end end |