aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorChristian Bäuerlein <fabrik42@gmail.com>2011-10-14 16:28:02 +0200
committerChristian Bäuerlein <fabrik42@gmail.com>2011-10-14 16:28:02 +0200
commit410fa4cf7c710ff062c59c1c90357729c418be65 (patch)
treea7fa601845f6de15ae53f9e23049559959432ead /activerecord/lib
parent401d00d296c0c4dafd0e1103051f6adf0ae56fc5 (diff)
downloadrails-410fa4cf7c710ff062c59c1c90357729c418be65.tar.gz
rails-410fa4cf7c710ff062c59c1c90357729c418be65.tar.bz2
rails-410fa4cf7c710ff062c59c1c90357729c418be65.zip
Includes stale record in StaleObjectError
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/errors.rb9
-rw-r--r--activerecord/lib/active_record/locking/optimistic.rb4
2 files changed, 11 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/errors.rb b/activerecord/lib/active_record/errors.rb
index 96870cb338..950fc7356c 100644
--- a/activerecord/lib/active_record/errors.rb
+++ b/activerecord/lib/active_record/errors.rb
@@ -99,6 +99,15 @@ module ActiveRecord
#
# Read more about optimistic locking in ActiveRecord::Locking module RDoc.
class StaleObjectError < ActiveRecordError
+ attr_reader :record
+
+ def initialize(record)
+ @record = record
+ end
+
+ def message
+ "Attempted to update a stale object: #{record.class.name}"
+ end
end
# Raised when association is being configured improperly or
diff --git a/activerecord/lib/active_record/locking/optimistic.rb b/activerecord/lib/active_record/locking/optimistic.rb
index d9ad7e4132..cafe48cff6 100644
--- a/activerecord/lib/active_record/locking/optimistic.rb
+++ b/activerecord/lib/active_record/locking/optimistic.rb
@@ -103,7 +103,7 @@ module ActiveRecord
affected_rows = connection.update stmt
unless affected_rows == 1
- raise ActiveRecord::StaleObjectError, "Attempted to update a stale object: #{self.class.name}"
+ raise ActiveRecord::StaleObjectError, self
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, "Attempted to delete a stale object: #{self.class.name}"
+ raise ActiveRecord::StaleObjectError, self
end
end