multiple key / values work
This commit is contained in:
parent
776af48acb
commit
135b3a0dde
@ -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:
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user