The push call will not mark that person dirty. You have to call person.addresses_will_change before save.This is tidies, and the reason for this is that the dirty module intercepts if an attribute changes. When you do the push operation you are getting the addresses array and you do something on that object, not on the MassiveRecord record.
We have a couple of solutions for this:
Work out a way to detect changes in the array (or hashes). Returning some kind of proxy which detect changes. This might be some work as arrays and hashes can be nested.
Don't try to detect changes, and treat all serialized arrays/hashes as dirty when we save. As far as I can remember this is the tactic done by ActiveRecord when to serialize :an_attribute.
Given we have the following class
And we do:
The push call will not mark that person dirty. You have to call
person.addresses_will_change
before save.This is tidies, and the reason for this is that the dirty module intercepts if an attribute changes. When you do the push operation you are getting the addresses array and you do something on that object, not on the MassiveRecord record.We have a couple of solutions for this:
serialize :an_attribute
...anything else we might do? :-)