Skip to content

Add support changing swapped_id, when called # destroy.#110

Merged
motsat merged 2 commits intokufu:masterfrom
motsat:changing_swapped_id_when_destroy
Jan 11, 2023
Merged

Add support changing swapped_id, when called # destroy.#110
motsat merged 2 commits intokufu:masterfrom
motsat:changing_swapped_id_when_destroy

Conversation

@motsat
Copy link
Copy Markdown
Member

@motsat motsat commented Dec 23, 2022

updated after #destroy but not swapped_id.
As a use case, I'm thinking of referencing swapped_id in the destroyed model callback(after_destroy) and saving it to another table.

class Employee < ActiveRecord::Base
  include ActiveRecord::Bitemporal

  after_destroy do
    # save the swapped_id of the event after destroy
    Event.create(event: :destroy, after_swapped_id:  swapped_id)
  end
end

employee = nil

employee = Employee.create(name: "Jane")
pp employee.swapped_id
# => 1
employee.destroy
pp employee.swapped_id
# Before => 1
# After => 2

@auto-assign auto-assign bot requested review from osyo-manga and wata727 December 23, 2022 04:35
}
raise ActiveRecord::RecordInvalid unless @destroyed

@_swapped_id = duplicated_instance.swapped_id
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is the swapped_id be assigned when after_destroy is called?
Intuitively, after_destroy is called after _run_destroy_callback, it seems that the swapped_id is not assigned at that time.

Copy link
Copy Markdown
Contributor

@wata727 wata727 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
Copy Markdown
Collaborator

@osyo-manga osyo-manga left a comment

Choose a reason for hiding this comment

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

OK, Thanks!

@motsat motsat merged commit c4b2381 into kufu:master Jan 11, 2023
@motsat motsat deleted the changing_swapped_id_when_destroy branch January 11, 2023 01:37
@motsat motsat mentioned this pull request Jan 11, 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.

3 participants