clear rolled back versions from associated model #440
Merged
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.
I propose this change to fix an issue where, under the right circumstances, version records are created for changes that never took place. Let's say I have two models,
Item
andLocation
, and attempt to save changes in a transaction:The
Item
model herehas_paper_trail
. A version is created for the item'supdate_attributes!
call is created and then rolled back, as expected. However, if we rescue from the error that happens when we runLocation.first.update_attributes!
and then callitem.save
, the rolled back version created when we tried to update the sku in a transaction is also saved - even though the sku on the item is not changed.An alternative approach - could try setting
autosave: false
inhas_paper_trail