Support conditional paper trail on destroy #168
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.
Howdy!
Background: We have a paper-trailed
Contact
model whichhas_many :email_addresses
. TheEmailAddress
model also has a paper trail. We have a custom way of undo-ing deletes of parents, and all their children.Problem: If someone blanks out an email in the web UI, then we destroy that email row. But, we don't want a
EmailAddress
version to be created in that case.Other problem: However, we do want to save a version of both the
EmailAddress
and theContact
, when a contact is deleted.Solution: Pass along the
:if
conditional to the destroy code. We have a conditional expression that knows the difference between the parentContact
delete, versus the one-off deletion of anEmailAddress
due to blanking it out in the UI.Thanks!