rails: Rails 3.2.7 - update_column breaks Hash-serialized attributes
I just upgraded to Rails 3.2.7 and found an interesting bug (maybe).
As you know, there is a deprecation warning (since v3.2.7) for using “update_attribute”. So I changed that to update_column everywhere my tests yielded.
For some of my model attributes I’m using “serialize ATTR_NAME”. Hashes are serialized in those attributes. The problem is that if I switch to update_column from update_attribute - Hashes are serialized into Arrays.
So, my model ends up with “attribute == [key, value]” instead of “attribute == {key => value}” after update_column on an serialized attribute.
I just wrote a work-around for that case:
model.send "#{attr}=", hash
model.save!
… however it would be nice if we fix update_column.
About this issue
- Original URL
- State: closed
- Created 12 years ago
- Comments: 21 (11 by maintainers)
Hi, a solution to use the update_column method instead of update_attribute to avoid the callbacks is to cast the hash with to_yaml . Tested on Rails 3.2.13