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

Update valid_to after #update #105

Merged
merged 1 commit into from
Dec 1, 2022

Conversation

motsat
Copy link
Member

@motsat motsat commented Nov 25, 2022

Fixed valid_from is updated after #update but not valid_to.
As a use case, I'm thinking of referencing valid_to in the updated model callback(after_update) and saving it to another table.

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

  after_update do
    # save the valid_from / valid_to of the event after updating
    Event.create(event: :update, valid_from: valid_from, valid_to: valid_to)
  end
end

employee = nil

ActiveRecord::Bitemporal.valid_at("2019/05/01") {
  employee = Employee.create(name: "Jane")
}
ActiveRecord::Bitemporal.valid_at("2019/04/01") {
  employee.update(name: "Jane")
}

update_event = Event.where(event: :update).order(:created_at).last
# Not updated transaction_from
# Will be updated transaction_from, after fixed
pp update_event.valid_to.to_time
# Before => 9999-12-31 09:00:00 +0900
# After  => 2019-05-01 09:00:00 +0900

@motsat motsat force-pushed the update-valid_to-after-update branch from 4098d93 to 4ebfaac Compare November 25, 2022 07:08
@motsat motsat force-pushed the update-valid_to-after-update branch from 4ebfaac to ee8aef7 Compare November 25, 2022 07:54
@motsat motsat marked this pull request as ready for review November 29, 2022 06:30
@auto-assign auto-assign bot requested review from kouryou and yono November 29, 2022 06:30
Copy link
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, Good.

@motsat motsat merged commit 5e572b2 into kufu:master Dec 1, 2022
@motsat motsat deleted the update-valid_to-after-update branch December 1, 2022 00:40
This was referenced Dec 2, 2022
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