1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Docfix (closes #8096)

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7107 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
David Heinemeier Hansson 2007-06-23 17:52:50 +00:00
parent b00e6a984d
commit 1a0cdf74be

View file

@ -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