Also support writing the hstore back to the database

This commit is contained in:
Joel 2012-02-08 14:21:10 -08:00
parent 5b318a84e7
commit 2dd0178229
2 changed files with 13 additions and 0 deletions

View File

@ -476,6 +476,11 @@ module ActiveRecord
return super unless column
case value
when Hash
case column.sql_type
when 'hstore' then super(PostgreSQLColumn.hstore_to_string(value), column)
else super
end
when Float
return super unless value.infinite? && column.type == :datetime
"'#{value.to_s.downcase}'"

View File

@ -86,6 +86,14 @@ class PostgresqlHstoreTest < ActiveRecord::TestCase
assert_equal({"\"a"=>"q\"w"}, @column.type_cast('\"a=>q"w'))
end
def test_rewrite
@connection.execute "insert into hstores (tags) VALUES ('1=>2')"
x = Hstore.find :first
x.tags = { '"a\'' => 'b' }
assert x.save!
end
def test_select
@connection.execute "insert into hstores (tags) VALUES ('1=>2')"
x = Hstore.find :first