diff options
author | Ernie Miller <ernie@erniemiller.org> | 2015-05-29 10:15:31 -0400 |
---|---|---|
committer | Ernie Miller <ernie@erniemiller.org> | 2015-05-29 10:15:31 -0400 |
commit | bbdcbbc98e997e34f4cf7e9a0a0046744911b5a0 (patch) | |
tree | d5bcb74f04d214c80b91e34186fb686a73de2fc2 /activerecord/lib/active_record/attribute_methods | |
parent | f5559111b55d99a2862b83eed6f2882b2f59bbd9 (diff) | |
download | rails-bbdcbbc98e997e34f4cf7e9a0a0046744911b5a0.tar.gz rails-bbdcbbc98e997e34f4cf7e9a0a0046744911b5a0.tar.bz2 rails-bbdcbbc98e997e34f4cf7e9a0a0046744911b5a0.zip |
Update docs for ActiveRecord `serialize`
For certain column types, using `serialize` is unnecessary, or the user
may get unexpected contents back from the DB adapter (which is handling
some basic deserialization for them). Call this out in the
documentation.
For background, see:
https://gist.github.com/ernie/33f75f2294885b9806f9
https://twitter.com/erniemiller/status/604262907442905090
Diffstat (limited to 'activerecord/lib/active_record/attribute_methods')
-rw-r--r-- | activerecord/lib/active_record/attribute_methods/serialization.rb | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/serialization.rb b/activerecord/lib/active_record/attribute_methods/serialization.rb index d0d8a968c5..216808b510 100644 --- a/activerecord/lib/active_record/attribute_methods/serialization.rb +++ b/activerecord/lib/active_record/attribute_methods/serialization.rb @@ -11,6 +11,15 @@ module ActiveRecord # serialized object must be of that class on assignment and retrieval. # Otherwise <tt>SerializationTypeMismatch</tt> will be raised. # + # Keep in mind that database adapters handle certain serialization tasks + # for you. For instance: +json+ and +sonb+ types in PostgreSQL will be + # converted between JSON object/array syntax and Ruby +Hash+ or +Array+ + # objects transparently. There is no need to use +serialize+ in this + # case. + # + # For more complex cases, such as conversion to or from your application + # domain objects, consider using the ActiveRecord::Attributes API. + # # ==== Parameters # # * +attr_name+ - The field name that should be serialized. |