Closed jerith closed 9 years ago
This approach doesn't handle multiple index values, so I need to do something different here. Sorry. :-/
This is ready for another review.
:+1: from me :)
Why don't we just update the value on get
or save
instead of every time someone updates any field on the model?
Why don't we just update the value on
get
orsave
instead of every time someone updates any field on the model?
I tried that before switching to update-on-value-change and ran into problems trying to intercept all accesses to object data (including things that look into the the underlying Riak object directly) to make sure updates didn't get missed. It ended up being cleaner doing it this way.
I tried that before switching to update-on-value-change and ran into problems trying to intercept all accesses to object data (including things that look into the the underlying Riak object directly) to make sure updates didn't get missed. It ended up being cleaner doing it this way.
But the only get
we need to worry about is getting the computed value itself? Having a pre-save hook might also allow us to add cross-field validation later, which would be cool.
But the only
get
we need to worry about is getting the computed value itself? Having a pre-save hook might also allow us to add cross-field validation later, which would be cool.
We need to make sure that everything we do with the object data, including the low-level operations that bypass fields (saving, migration, etc.) has the right values and metadata for all fields. Hooking into the various things that read that is harder than triggering updates on writes through the model object. (As I said, I tried this and it ended up being more complicated than I was happy with.)
More importantly, it's a good idea to catch validation or computation errors when the data is modified instead of some future time when we try to read a field or save the object.
One can't do cross-field validation when a single field is updated.
This PR isn't about cross-field validation. Even if it were, we'd want the validation to happen before the update and not at the next read or save at some arbitrary point in the future.
:+1:
We currently do this very hackily in places and a cleaner solution would be good.