I followed the example in the AR changelog about how to set up serialization of columns with Type checking but I always get the following Error: irb(main):002:0> c.notes TypeError: class or module required from /usr/lib/ruby/site_ruby/1.8/active_record/base.rb:819:in `is_a?'' from /usr/lib/ruby/site_ruby/1.8/active_record/base.rb:819:in `unserialize_attribute'' from /usr/lib/ruby/site_ruby/1.8/active_record/base.rb:804:in `read_attribute'' from ./config/environments/../../app/models/change.rb:100:in `notes'' from (irb):2 My model looks like this: class Change < ActiveRecord::Base serialize :notes, :class_name => "Hash" end I''ve checked and the notes cell contains a yamlized hash. I tracked the problem down to the serialize method in active_record/base.rb (405). After looking there I changed my model to: class Change < ActiveRecord::Base serialize :notes, Hash end And this seems to work, ie I get a ActiveRecord::SerializationTypeMismatch when I should. Should the docs or code be updated?
> And this seems to work, ie I get a > ActiveRecord::SerializationTypeMismatch when I should. > > Should the docs or code be updated?The code should be updated. This certainly sounds like a bug. -- David Heinemeier Hansson, http://www.basecamphq.com/ -- Web-based Project Management http://www.rubyonrails.org/ -- Web-application framework for Ruby http://macromates.com/ -- TextMate: Code and markup editor (OS X) http://www.loudthinking.com/ -- Broadcasting Brain
Should AR check the type when you save the record too? for example, using my model: change.notes = [] change.save # throws an exception David Heinemeier Hansson wrote:>> And this seems to work, ie I get a >> ActiveRecord::SerializationTypeMismatch when I should. >> >> Should the docs or code be updated? > > > The code should be updated. This certainly sounds like a bug. > -- > David Heinemeier Hansson, > http://www.basecamphq.com/ -- Web-based Project Management > http://www.rubyonrails.org/ -- Web-application framework for Ruby > http://macromates.com/ -- TextMate: Code and markup editor (OS X) > http://www.loudthinking.com/ -- Broadcasting Brain > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Daniel Hobe <daniel-Rb441GAJvreWkzVdRvz7FA@public.gmane.org> http://www.nightrunner.com
> Should AR check the type when you save the record too?I was thinking about that. It''s currently a bit inconvenient to do so because the knowledge sits in Base while saving happens in one of the adapters that aren''t directly aware of Base. I''d welcome a clean patch that makes this happen, though. -- David Heinemeier Hansson, http://www.basecamphq.com/ -- Web-based Project Management http://www.rubyonrails.org/ -- Web-application framework for Ruby http://macromates.com/ -- TextMate: Code and markup editor (OS X) http://www.loudthinking.com/ -- Broadcasting Brain