提交 e835596a 编写于 作者: J Jakob Skjerning

Clear attribute changes after handling locking

Without this the changes to the lock version column will stick around
even after `touch` returns.

Before:

    model.touch
    model.changes
    # => {"lock_version"=>[0, "1"]}

After:

    model.touch
    model.changes
    # {}
上级 1d7b00d6
* Calling `touch` on a model using optimistic locking will now leave the model
in a non-dirty state with no attribute changes.
Fixes #26496.
*Jakob Skjerning*
* Using a mysql2 connection after it fails to reconnect will now have an error message
saying the connection is closed rather than an undefined method error message.
......
......@@ -498,7 +498,6 @@ def touch(*names, time: nil)
changes[column] = write_attribute(column, time)
end
clear_attribute_changes(changes.keys)
primary_key = self.class.primary_key
scope = self.class.unscoped.where(primary_key => _read_attribute(primary_key))
......@@ -508,6 +507,7 @@ def touch(*names, time: nil)
changes[locking_column] = increment_lock
end
clear_attribute_changes(changes.keys)
result = scope.update_all(changes) == 1
if !result && locking_enabled?
......
......@@ -181,6 +181,7 @@ def test_touch_existing_lock
p1.touch
assert_equal 1, p1.lock_version
assert_not p1.changed?, "Changes should have been cleared"
end
def test_touch_stale_object
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册