From 1f06652a57e727700c3a673dc1f86e3b1e07ce1f Mon Sep 17 00:00:00 2001 From: David Chelimsky Date: Sun, 7 Nov 2010 08:05:18 -0600 Subject: use persisted? instead of new_record? wherever possible - persisted? is the API defined in ActiveModel - makes it easier for extension libraries to conform to ActiveModel APIs without concern for whether the extended object is specifically ActiveRecord [#5927 state:committed] Signed-off-by: Santiago Pastorino --- activerecord/lib/active_record/locking/optimistic.rb | 2 +- activerecord/lib/active_record/locking/pessimistic.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'activerecord/lib/active_record/locking') diff --git a/activerecord/lib/active_record/locking/optimistic.rb b/activerecord/lib/active_record/locking/optimistic.rb index b6f87a57b8..bf626301f1 100644 --- a/activerecord/lib/active_record/locking/optimistic.rb +++ b/activerecord/lib/active_record/locking/optimistic.rb @@ -109,7 +109,7 @@ module ActiveRecord def destroy #:nodoc: return super unless locking_enabled? - unless new_record? + if persisted? lock_col = self.class.locking_column previous_value = send(lock_col).to_i diff --git a/activerecord/lib/active_record/locking/pessimistic.rb b/activerecord/lib/active_record/locking/pessimistic.rb index 9ad6a2baf7..d900831e13 100644 --- a/activerecord/lib/active_record/locking/pessimistic.rb +++ b/activerecord/lib/active_record/locking/pessimistic.rb @@ -47,7 +47,7 @@ module ActiveRecord # or pass true for "FOR UPDATE" (the default, an exclusive row lock). Returns # the locked record. def lock!(lock = true) - reload(:lock => lock) unless new_record? + reload(:lock => lock) if persisted? self end end -- cgit v1.2.3