Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Consider attempted action in exception message of ActiveRecord::Stale…

…ObjectError
  • Loading branch information...
commit c6f0461e898601578fa8160608d19fec319067fa 1 parent 410fa4c
@fabrik42 fabrik42 authored
View
9 activerecord/lib/active_record/errors.rb
@@ -99,15 +99,16 @@ class PreparedStatementInvalid < ActiveRecordError
#
# 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
View
4 activerecord/lib/active_record/locking/optimistic.rb
@@ -103,7 +103,7 @@ def update(attribute_names = @attributes.keys) #:nodoc:
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 @@ def destroy #:nodoc:
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
Please sign in to comment.
Something went wrong with that request. Please try again.