Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Don't create local vars.

  • Loading branch information...
commit d29d793c9096a732274298cdba07c654e9128484 1 parent 6ffe0ef
@miloops miloops authored tenderlove committed
Showing with 1 addition and 4 deletions.
  1. +1 −4 activerecord/lib/active_record/locking/optimistic.rb
5 activerecord/lib/active_record/locking/optimistic.rb
@@ -110,12 +110,9 @@ def destroy #:nodoc:
return super unless locking_enabled?
if persisted?
- lock_col = self.class.locking_column
- previous_value = send(lock_col).to_i
table = self.class.arel_table
predicate = table[self.class.primary_key].eq(id)
- predicate = predicate.and(table[self.class.locking_column].eq(previous_value))
+ predicate = predicate.and(table[self.class.locking_column].eq(send(self.class.locking_column).to_i))

Code duplication. May be better that?

lock_col = self.class.locking_column
predicate = predicate.and(table[lock_col].eq(send(lock_col).to_i))

@tenderlove Owner

I agree. That would have been better.

miloops added a note

yeah, i saw lock_col was used just once but instead removing it would be better to reuse it. previous_value should still be removed tho.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
affected_rows = self.class.unscoped.where(predicate).delete_all

0 comments on commit d29d793

Please sign in to comment.
Something went wrong with that request. Please try again.