diff options
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 527c2fef5a..9d2e186672 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -640,9 +640,21 @@ module ActiveRecord #:nodoc: end - # Specifies that the attribute by the name of +attr_name+ should be serialized before saving to the database and unserialized - # after loading from the database. The serialization is done through YAML. If +class_name+ is specified, the serialized - # object must be of that class on retrieval, or nil. Otherwise, +SerializationTypeMismatch+ will be raised. + # If you have an attribute that needs to be saved to the database as an object, and retrieved as the same object, + # then specify the name of that attribute using this method and it will be handled automatically. + # The serialization is done through YAML. If +class_name+ is specified, the serialized object must be of that + # class on retrieval or +SerializationTypeMismatch+ will be raised. + # + # ==== Options + # + # +attr_name+ The field name that should be serialized + # +class_name+ Optional, class name that the object should be equal to + # + # ==== Example + # # Serialize a preferences attribute + # class User + # serialize :preferences + # end def serialize(attr_name, class_name = Object) serialized_attributes[attr_name.to_s] = class_name end |