提交 2159a932 编写于 作者: E Eileen M. Uchitelle 提交者: GitHub

Merge pull request #26497 from koppen/26496-touch_with_optimistic_locking

Clear attribute changes after handling locking
* 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.
先完成此消息的编辑!
想要评论请 注册