diff options
Diffstat (limited to 'activerecord')
-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 |