Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add previously_force_updated? #142

Merged
merged 1 commit into from
Aug 7, 2023
Merged

Conversation

wata727
Copy link
Contributor

@wata727 wata727 commented Jul 28, 2023

This PR adds a previously_force_updated? method like ActiveModel::Dirty#*_previously_changed?.

employee = Employee.create!(name: "Jone")
employee.previously_force_updated? # => false

employee.force_update { |e| e.update!(name: "Tom") }
employee.previously_force_updated? # => true

employee.update!(name: "Kevin")
employee.previously_force_updated? # => false

employee.force_update { |e| e.destroy! }
employee.destroyed?     # => true
employee.previously_force_updated? # => true

This is the only right way to determine that history has been rewritten by force updating. Previously there was no way to determine that this was done outside of the force_update block.

side note: It was originally named force_updated? in reference to ActiveRecord::Persistence#destroyed?, but it is too similar to force_update?, so previously_force_updated? was adopted.

@auto-assign auto-assign bot requested review from Dooor and krororo July 28, 2023 09:59
@wata727 wata727 changed the title Add force_updated? Add previously_force_updated? Jul 31, 2023
Copy link
Contributor

@krororo krororo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor

@Dooor Dooor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@wata727 wata727 merged commit b9763b1 into kufu:master Aug 7, 2023
7 of 10 checks passed
@wata727 wata727 deleted the force_updated branch August 7, 2023 07:17
@wata727 wata727 mentioned this pull request Aug 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants