activerecord-bitemporal icon indicating copy to clipboard operation
activerecord-bitemporal copied to clipboard

Apply irrelevant changes caused by touch

Open wata727 opened this issue 2 years ago • 1 comments

While doing some research, I noticed that models that include ActiveRecord::Bitemporal have unintended changes after being touched:

# bitemporal
employee.changes.keys # => []
employee.touch
employee.changes.keys # => ["valid_from", "transaction_from"]
employee.saved_changes.keys # => ["updated_at"]

# non-bitemporal
book.changes.keys # => []
book.touch
book,changes.keys # => []
book.saved_changes.keys # => ["updated_at"]

Perhaps adding changes unintentionally is not the expected behavior.

This PR changes the changes caused by touch to be moved saved_changes:

employee.changes.keys # => []
employee.touch
employee.changes.keys # => []
employee.saved_changes.keys # => ["valid_from", "transaction_from", "updated_at"]

As a side note, I noticed that unlike the non-bitemporal model, there was an issue where the dirty state before touch was unintentionally saved, but that's an issue that should be addressed in another PR.

wata727 avatar Jul 19 '23 11:07 wata727

This PR is frozen because #148 may fix this issue.

wata727 avatar Oct 10 '23 10:10 wata727