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 InstanceMethods#swapped_id_previously_was #114

Merged
merged 1 commit into from
Jan 27, 2023

Conversation

wata727
Copy link
Contributor

@wata727 wata727 commented Jan 23, 2023

This PR adds a new instance method called swapped_id_previously_was. This allows you to get the previous swapped_id after the update/destroy:

employee = Employee.create!(name: 'John')
employee.swapped_id # => 1
employee.swapped_id_previously_was # => nil

employee.update!(name: 'Sam')
employee.swapped_id # => 2
employee.swapped_id_previously_was # => 1

employee.reload
employee.swapped_id # => 2
employee.swapped_id_previously_was # => nil

employee.destroy!
employee.swapped_id # => 3
employee.swapped_id_previously_was # => 2

This is useful for retrieving before/after values delta from an updated instance. The naming is inspired by ActiveModel::Dirty.

It is intentional that swapped_id_was is undefined because the swapped_id is not basically assumed to be rewritten from the outside.

@wata727 wata727 requested review from motsat and Dooor and removed request for kouryou January 23, 2023 09:54
Copy link
Member

@motsat motsat left a comment

Choose a reason for hiding this comment

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

LGTM 👍

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.

LGTM 🎉

@wata727 wata727 merged commit ed15e16 into kufu:master Jan 27, 2023
@wata727 wata727 deleted the dirty_swapped_id branch January 27, 2023 06:31
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