mirror of https://github.com/rails/rails
Also support writing the hstore back to the database
This commit is contained in:
parent
5b318a84e7
commit
2dd0178229
|
@ -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}'"
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue