Rails Bug: Saving Only "changed" Attributes Hurts Serialization
Really unhappy with this bug. I hope the Rails team agrees that this is a bug unlike my last “bug” report.
If you’re unfarmiliar with “changed?” attribute updating I recommend reading Living on the edge (of Rails) #14 before continuing.
Here it is, the nasty:
class Node < ActiveRecord::Base
serialize :data
end>> n = Node.create! :data => { :a => 1 }
=> #<Node id: 417950, data: {:a=>1}>
>> n.id
=> 417950
>> m = Node.find 417950
=> #<Node id: 417950, data: {:a=>1}>
>> m.data[:b] = 2
=> 2
>> m
=> #<Node id: 417950, data: {:b=>2, :a=>1}>
>> m.changed?
=> false
>> m.save!
=> true
>> m = Node.find 417950
=> #<Node id: 417950, data: {:a=>1}>Changes to the hash are never saved and that makes me really, really sad.
I’ve opened a ticket.