diff options
author | Yves Senn <yves.senn@gmail.com> | 2014-05-28 13:32:40 +0200 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2014-05-28 13:35:02 +0200 |
commit | bdbf00dc78869f91a8af4d56a19213faf2b8d9e5 (patch) | |
tree | bb9e53068d5fb30ea7c038888d531d0673f1e7d6 /activerecord/lib | |
parent | 7f73b9152cfc3f218cfc862e971ba56b94f6be10 (diff) | |
download | rails-bdbf00dc78869f91a8af4d56a19213faf2b8d9e5.tar.gz rails-bdbf00dc78869f91a8af4d56a19213faf2b8d9e5.tar.bz2 rails-bdbf00dc78869f91a8af4d56a19213faf2b8d9e5.zip |
pg, keep `hstore` and `json` attributes as `Hash` in @attributes.
The solution presented in this patch is not efficient. We should replace it
in the near future. The following needs to be worked out:
* Is `@attributes` storing the Ruby or SQL representation?
* `cacheable_column?` is broken but `hstore` and `json` rely on that behavior
Refs #15369.
/cc @sgrif @rafaelfranca
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/oid/hstore.rb | 8 | ||||
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/oid/json.rb | 8 |
2 files changed, 14 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid/hstore.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid/hstore.rb index 98f369a7f8..bf680b6624 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid/hstore.rb @@ -8,7 +8,13 @@ module ActiveRecord end def type_cast_for_write(value) - ConnectionAdapters::PostgreSQLColumn.hstore_to_string value + # roundtrip to ensure uniform uniform types + # TODO: This is not an efficient solution. + cast_value(type_cast_for_database(value)) + end + + def type_cast_for_database(value) + ConnectionAdapters::PostgreSQLColumn.hstore_to_string(value) end def cast_value(value) diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid/json.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid/json.rb index 42bf5656f4..42a5110ffd 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/oid/json.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid/json.rb @@ -8,7 +8,13 @@ module ActiveRecord end def type_cast_for_write(value) - ConnectionAdapters::PostgreSQLColumn.json_to_string value + # roundtrip to ensure uniform uniform types + # TODO: This is not an efficient solution. + cast_value(type_cast_for_database(value)) + end + + def type_cast_for_database(value) + ConnectionAdapters::PostgreSQLColumn.json_to_string(value) end def cast_value(value) |