I want to call a hook, even if object is not dirty.
For example to calculate an attribute based on children:
class Store
include DataMapper::Resource
has n, :store_lines
property :id, Serial
property :name, String
property :lines, Integer
before :save, :sum_lines
def sum_lines
self.lines = self.store_lines.size
end
end
If I add a new line to the store, and call "store.save", the "lines"
attribute is never recreated, because the object is not dirty itself.
I see two options:
1) mark it as dirty by using something like: "store.dirty =
true" (this does not exist currently)
2) call "store.sum_lines" before "store.save", but this option will
call "sum_lines" two times in a row.
would be nice having this option:
before :save, :sum_lines, :mandatory => true
so it is always called, even if the object is not dirty.
--
You received this message because you are subscribed to the Google Groups
"DataMapper" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/datamapper?hl=en.