aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/locking/optimistic.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2008-03-31 01:10:04 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2008-03-31 01:10:04 +0000
commit6b9448cdd227ef3adbe2f31ecaf64bc7ef062103 (patch)
tree6814f2520554eef1b7ed69e4e284db44d00d7fd9 /activerecord/lib/active_record/locking/optimistic.rb
parent2cf72ad250f7c393e6aa97384768ed803686eb97 (diff)
downloadrails-6b9448cdd227ef3adbe2f31ecaf64bc7ef062103.tar.gz
rails-6b9448cdd227ef3adbe2f31ecaf64bc7ef062103.tar.bz2
rails-6b9448cdd227ef3adbe2f31ecaf64bc7ef062103.zip
Partial updates include only unsaved attributes. Off by default; set YourClass.partial_updates = true to enable.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9157 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/locking/optimistic.rb')
-rw-r--r--activerecord/lib/active_record/locking/optimistic.rb9
1 files changed, 6 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/locking/optimistic.rb b/activerecord/lib/active_record/locking/optimistic.rb
index 799309c17b..f2c2c5f070 100644
--- a/activerecord/lib/active_record/locking/optimistic.rb
+++ b/activerecord/lib/active_record/locking/optimistic.rb
@@ -66,17 +66,20 @@ module ActiveRecord
return result
end
- def update_with_lock #:nodoc:
- return update_without_lock unless locking_enabled?
+ def update_with_lock(attribute_names = @attributes.keys) #:nodoc:
+ return update_without_lock(attribute_names) unless locking_enabled?
lock_col = self.class.locking_column
previous_value = send(lock_col).to_i
send(lock_col + '=', previous_value + 1)
+ attribute_names += [lock_col]
+ attribute_names.uniq!
+
begin
affected_rows = connection.update(<<-end_sql, "#{self.class.name} Update with optimistic locking")
UPDATE #{self.class.table_name}
- SET #{quoted_comma_pair_list(connection, attributes_with_quotes(false, false))}
+ SET #{quoted_comma_pair_list(connection, attributes_with_quotes(false, false, attribute_names))}
WHERE #{self.class.primary_key} = #{quote_value(id)}
AND #{self.class.quoted_locking_column} = #{quote_value(previous_value)}
end_sql