I don't understand the following example from the ActiveRecord::Base
section in http://api.rubyonrails.org/ :

======
class User < ActiveRecord::Base
  serialize :preferences, Hash
end

user = User.create(preferences: %w( one two three ))
User.find(user.id).preferences    # raises SerializationTypeMismatch
======

What was the design choice, that I get the exception in the *last* line?
I could understand, if there is an exception in User.create, because
:preferences is supposed to be a Hash (if I understood correctly the
'serialize' function), and instead an Array is passed. But the
documentation clearly says that the exception happens at retrieval:

======
You can also specify a class option as the second parameter that'll
raise an exception if a serialized object is retrieved as a descendant
of a class not in the hierarchy.
======

Is there a deeper reason, why this error is caught at retrieval, and not
already at the time of storing the value?

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/7e006639e4c9ebde871d76fe63d3b1c1%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to