Permalink
Browse files

Reuse lock_col variable instead calling locking_column class method.

Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
  • Loading branch information...
1 parent 731ca00 commit c4d31d0f13783f3cfadbde666fd2a06996b456a2 @miloops miloops committed with spastorino Nov 25, 2010
Showing with 4 additions and 3 deletions.
  1. +4 −3 activerecord/lib/active_record/locking/optimistic.rb
@@ -89,7 +89,7 @@ def update(attribute_names = @attributes.keys) #:nodoc:
affected_rows = relation.where(
relation.table[self.class.primary_key].eq(quoted_id).and(
- relation.table[self.class.locking_column].eq(quote_value(previous_value))
+ relation.table[lock_col].eq(quote_value(previous_value))
)
).arel.update(arel_attributes_values(false, false, attribute_names))
@@ -111,8 +111,9 @@ def destroy #:nodoc:
if persisted?
table = self.class.arel_table
- predicate = table[self.class.primary_key].eq(id)
- predicate = predicate.and(table[self.class.locking_column].eq(send(self.class.locking_column).to_i))
+ lock_col = self.class.locking_column
+ predicate = table[self.class.primary_key].eq(id).
+ and(table[lock_col].eq(send(lock_col).to_i))
affected_rows = self.class.unscoped.where(predicate).delete_all

0 comments on commit c4d31d0

Please sign in to comment.