From 83752373b9c83bf585b5fe44836c65612b680cf9 Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Wed, 7 Feb 2007 16:10:40 +0000 Subject: Made increment_counter/decrement_counter play nicely with optimistic locking, and added a more general update_counters method git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6139 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../lib/active_record/locking/optimistic.rb | 25 ++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'activerecord/lib/active_record/locking/optimistic.rb') diff --git a/activerecord/lib/active_record/locking/optimistic.rb b/activerecord/lib/active_record/locking/optimistic.rb index 02cf565017..217bd3def7 100644 --- a/activerecord/lib/active_record/locking/optimistic.rb +++ b/activerecord/lib/active_record/locking/optimistic.rb @@ -31,14 +31,14 @@ module ActiveRecord base.alias_method_chain :update, :lock base.alias_method_chain :attributes_from_column_definition, :lock - + class << base alias_method :locking_column=, :set_locking_column end end def locking_enabled? #:nodoc: - lock_optimistically && respond_to?(self.class.locking_column) + self.class.locking_enabled? end def attributes_from_column_definition_with_lock @@ -80,6 +80,20 @@ module ActiveRecord module ClassMethods DEFAULT_LOCKING_COLUMN = 'lock_version' + def self.extended(base) + class < 1) if locking_enabled? + update_counters_without_lock(id, counters) + end end end end -- cgit v1.2.3