CompanyBook / massive_record

HBase ruby client
130 stars 39 forks source link

Detect changes in array/hashes #52

Closed thhermansen closed 7 years ago

thhermansen commented 13 years ago

Given we have the following class

class Person < MassiveRecord::ORM::Table
    column_family :info do
      field :addresses, :array, :allow_nil => false
    end
end

And we do:

person = Person.find(1)
person.addresses << {:street => "Foo", :zip => 1122}

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:

  1. 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.
  2. 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.

..anything else we might do? :-)

thhermansen commented 7 years ago

Looks rather old. Closing it :-)