Skip to content

Update transaction_from after #update.#100

Closed
osyo-manga wants to merge 1 commit intokufu:masterfrom
osyo-manga:update-transaction_from-after-update
Closed

Update transaction_from after #update.#100
osyo-manga wants to merge 1 commit intokufu:masterfrom
osyo-manga:update-transaction_from-after-update

Conversation

@osyo-manga
Copy link
Copy Markdown
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)

@auto-assign auto-assign bot requested review from 16bitidol and wakasa51 September 16, 2022 00:59
@osyo-manga
Copy link
Copy Markdown
Collaborator Author

osyo-manga commented Sep 16, 2022

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

Copy link
Copy Markdown
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.

2 participants