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 transaction_from after #update. #100

Conversation

osyo-manga
Copy link
Collaborator

@osyo-manga osyo-manga commented Sep 16, 2022

Fixed valid_from is updated after #update but not transaction_from.

employee = nil

Timecop.freeze("2020/09/01") {
  valid_datetime = "2020/06/01"
  ActiveRecord::Bitemporal.valid_at("2020/06/01") {
    employee = Employee.create(name: "hoge")
  }
}

Timecop.freeze("2020/09/02") {
  ActiveRecord::Bitemporal.valid_at("2020/07/01") {
    pp employee.valid_from.to_time         # => 2020-06-01 09:00:00 +0900
    pp employee.transaction_from.to_time   # => 2020-09-01 09:00:00 +0900

    employee.update!(name: "foo")

    # Updated valid_from
    pp employee.valid_from.to_time         # => 2020-07-01 09:00:00 +0900

    # Not updated transaction_from
    # Will be updated transaction_from, after fixed
    pp employee.transaction_from.to_time
    # Before => 2020-09-01 09:00:00 +0900
    # After  => 2020-09-02 09:00:00 +0900
  }
}

Often there are cases where you want to get the actual system time of operation after an update.

employee.update!(name: "foo")
# want to see when `employee` was updated.
Event.create(event: :update, operated_at: employee.transaction_from)

@osyo-manga
Copy link
Collaborator Author

osyo-manga commented Sep 16, 2022

rails/rails#45908 causes database_cleaner to break and CI to fail 😭

Copy link
Member

@wakasa51 wakasa51 left a comment

Choose a reason for hiding this comment

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

👍

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

2 participants