Fixed model attribute synchronization for update method #2062
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Introduction
When model's
attributes
are modified during even hooks, e.g.on('save')
, changes are not detected and incorrectattributes
are persisted in the db.Motivation
As described in the #2007.
Proposed solution
The keep
.attributes
available for modification and avoid loosing reference to that object duringtriggerThen
stage we could refetch attributesToSave through a method instead of keeping an object around.Alternatives considered
Alternatively we could be explicit about not allowing to modify
attributes
directly by the bookshelf clients. This would mean forcing use ofset
(sometimes withunset
flag) method on the model to do any modifications. This approach is rather inflexible and would require clients to modify code.