Permalink
Browse files

multiple key / values work

  • Loading branch information...
1 parent 776af48 commit 135b3a0dde2edd013b666ab54d35b8b99220f0aa @tenderlove tenderlove committed Dec 20, 2011
View
5 activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -51,7 +51,10 @@ def string_to_time(string)
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:
View
6 activerecord/test/cases/adapters/postgresql/hstore_test.rb
@@ -37,4 +37,10 @@ def test_select
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

0 comments on commit 135b3a0

Please sign in to comment.