From 8bc464c8090f2929917ecd2d9476c914aa6da787 Mon Sep 17 00:00:00 2001 From: Franck Verrot Date: Sat, 27 Nov 2010 11:14:26 +0100 Subject: The optimistic lock column should be increased when calling touch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Santiago Pastorino and José Ignacio Costa --- activerecord/lib/active_record/persistence.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb index b05957981d..3fd67078b4 100644 --- a/activerecord/lib/active_record/persistence.rb +++ b/activerecord/lib/active_record/persistence.rb @@ -224,6 +224,7 @@ module ActiveRecord def touch(name = nil) attributes = timestamp_attributes_for_update_in_model attributes << name if name + unless attributes.empty? current_time = current_time_from_proper_timezone changes = {} @@ -232,6 +233,12 @@ module ActiveRecord changes[column.to_s] = write_attribute(column.to_s, current_time) end + if locking_enabled? + lock_col = self.class.locking_column.to_s + previous_value = send(lock_col).to_i + changes[lock_col] = write_attribute(lock_col, previous_value + 1) + end + @changed_attributes.except!(*changes.keys) primary_key = self.class.primary_key self.class.update_all(changes, { primary_key => self[primary_key] }) == 1 -- cgit v1.2.3