aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2013-08-07 15:17:15 +0200
committerYves Senn <yves.senn@gmail.com>2013-08-08 07:27:30 +0200
commit5ac2341fab689344991b2a4817bd2bc8b3edac9d (patch)
tree6779faa675a2a2e9cad6fd2e0a94cc5674f9b1d1 /activerecord/lib/active_record/connection_adapters
parent765b8aa05c2176ec8d12b623ffc3df330f4ea383 (diff)
downloadrails-5ac2341fab689344991b2a4817bd2bc8b3edac9d.tar.gz
rails-5ac2341fab689344991b2a4817bd2bc8b3edac9d.tar.bz2
rails-5ac2341fab689344991b2a4817bd2bc8b3edac9d.zip
cast hstore values on write to be consistent with reading from the db.
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters')
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/oid.rb8
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb8
2 files changed, 12 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb
index 1be116ce10..58c6235059 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb
@@ -6,10 +6,6 @@ module ActiveRecord
module OID
class Type
def type; end
-
- def type_cast_for_write(value)
- value
- end
end
class Identity < Type
@@ -224,6 +220,10 @@ module ActiveRecord
end
class Hstore < Type
+ def type_cast_for_write(value)
+ ConnectionAdapters::PostgreSQLColumn.hstore_to_string value
+ end
+
def type_cast(value)
return if value.nil?
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
index 342d1b1433..5b9453a579 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -129,6 +129,14 @@ module ActiveRecord
end
end
+ def type_cast_for_write(value)
+ if @oid_type.respond_to?(:type_cast_for_write)
+ @oid_type.type_cast_for_write(value)
+ else
+ super
+ end
+ end
+
def type_cast(value)
return if value.nil?
return super if encoded?