mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Consider attempted action in exception message of ActiveRecord::StaleObjectError
This commit is contained in:
parent
410fa4cf7c
commit
c6f0461e89
2 changed files with 7 additions and 6 deletions
|
@ -99,15 +99,16 @@ module ActiveRecord
|
|||
#
|
||||
# Read more about optimistic locking in ActiveRecord::Locking module RDoc.
|
||||
class StaleObjectError < ActiveRecordError
|
||||
attr_reader :record
|
||||
attr_reader :record, :attempted_action
|
||||
|
||||
def initialize(record)
|
||||
def initialize(record, attempted_action)
|
||||
@record = record
|
||||
@attempted_action = attempted_action
|
||||
end
|
||||
|
||||
def message
|
||||
"Attempted to update a stale object: #{record.class.name}"
|
||||
end
|
||||
"Attempted to #{attempted_action} a stale object: #{record.class.name}"
|
||||
end
|
||||
end
|
||||
|
||||
# Raised when association is being configured improperly or
|
||||
|
|
|
@ -103,7 +103,7 @@ module ActiveRecord
|
|||
affected_rows = connection.update stmt
|
||||
|
||||
unless affected_rows == 1
|
||||
raise ActiveRecord::StaleObjectError, self
|
||||
raise ActiveRecord::StaleObjectError.new(self, "update")
|
||||
end
|
||||
|
||||
affected_rows
|
||||
|
@ -127,7 +127,7 @@ module ActiveRecord
|
|||
affected_rows = self.class.unscoped.where(predicate).delete_all
|
||||
|
||||
unless affected_rows == 1
|
||||
raise ActiveRecord::StaleObjectError, self
|
||||
raise ActiveRecord::StaleObjectError.new(self, "destroy")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue