跳至內文 跳至搜尋

在嘗試儲存陳舊紀錄時引發。當在實體化後,另個查詢中加以儲存時,紀錄會變成陳舊。例如,當兩個使用者編輯同一個 wiki 頁面,其中一人開始編輯,並在另一人之前儲存頁面時。

進一步了解 ActiveRecord::Locking 模組文件中的樂觀鎖定。

方法
N

屬性

[R] attempted_action
[R] record

類別公開方法

new(record = nil, attempted_action = nil)

# File activerecord/lib/active_record/errors.rb, line 374
def initialize(record = nil, attempted_action = nil)
  if record && attempted_action
    @record = record
    @attempted_action = attempted_action
    super("Attempted to #{attempted_action} a stale object: #{record.class.name}.")
  else
    super("Stale object error.")
  end
end