aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2010-05-11 15:32:41 +0100
committerPratik Naik <pratiknaik@gmail.com>2010-05-11 15:32:41 +0100
commit475d1d1713faddee890e2367724a629169e079fe (patch)
tree4a69157548dceff695a8915ebfbef3345ba07766 /activerecord
parent1f675ea8c731328aa4ba14187ba529f0b53fbf0d (diff)
downloadrails-475d1d1713faddee890e2367724a629169e079fe.tar.gz
rails-475d1d1713faddee890e2367724a629169e079fe.tar.bz2
rails-475d1d1713faddee890e2367724a629169e079fe.zip
Use arel instead of sql strings
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/locking/optimistic.rb11
1 files changed, 5 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/locking/optimistic.rb b/activerecord/lib/active_record/locking/optimistic.rb
index 71057efa15..ceb0902fde 100644
--- a/activerecord/lib/active_record/locking/optimistic.rb
+++ b/activerecord/lib/active_record/locking/optimistic.rb
@@ -113,12 +113,11 @@ module ActiveRecord
lock_col = self.class.locking_column
previous_value = send(lock_col).to_i
- affected_rows = connection.delete(
- "DELETE FROM #{self.class.quoted_table_name} " +
- "WHERE #{connection.quote_column_name(self.class.primary_key)} = #{quoted_id} " +
- "AND #{self.class.quoted_locking_column} = #{quote_value(previous_value)}",
- "#{self.class.name} Destroy"
- )
+ table = self.class.arel_table
+ predicate = table[self.class.primary_key].eq(id)
+ predicate = predicate.and(table[self.class.locking_column].eq(previous_value))
+
+ affected_rows = self.class.unscoped.where(predicate).delete_all
unless affected_rows == 1
raise ActiveRecord::StaleObjectError, "Attempted to delete a stale object: #{self.class.name}"