couchrest/couchrest_model — Issue #130: Problem with Dirty when using dynamic properties
Author: doro
Created: 2011-11-17 12:04:00+00:00
State: open

I am using couchrest model (rails project), and i want to access attributes like this:

person = Person.get(some_id)
person["name"] = "joe"
person.update

and i don't want to define "name" as a property in the Person model. the problem is that the update doesn't work (the document is not updated in couchdb), since the document is not dirty.

the reason, i think, that the document doesn't get dirty when i use the []= method is because it doesn't go via the write_attribute method that uses the Dirty mechanism, but it goes via the []= method in CouchRest::Attributes module

one solution is to do:
person.disable_dirty = true # but that seems dirty.

another solution is to do something like that:
person.send("name=", "joe")

but that's even dirtier, especially if "name" reside in a variable, it will look something like that:
person.send("#{key}=", "joe")

is there a less dirty idea/solution re this issue?