aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activerecord/lib/active_record/locking/optimistic.rb24
-rw-r--r--activerecord/test/cases/locking_test.rb2
2 files changed, 7 insertions, 19 deletions
diff --git a/activerecord/lib/active_record/locking/optimistic.rb b/activerecord/lib/active_record/locking/optimistic.rb
index eb0bcff740..7bca38c910 100644
--- a/activerecord/lib/active_record/locking/optimistic.rb
+++ b/activerecord/lib/active_record/locking/optimistic.rb
@@ -80,24 +80,14 @@ module ActiveRecord
begin
relation = self.class.unscoped
- # FIXME: Remove the Arel::Nodes::Quoted when we remove type casting
- # from Arel (Rails 5.1)
- quoted_lock_value = Arel::Nodes::Quoted.new(
- self.class.quote_value(
- previous_lock_value,
- column_for_attribute(lock_col),
- )
+ affected_rows = relation.where(
+ self.class.primary_key => id,
+ lock_col => previous_lock_value,
+ ).update_all(
+ attribute_names.map do |name|
+ [name, _read_attribute(name)]
+ end.to_h
)
- quoted_id = Arel::Nodes::Quoted.new(id)
- stmt = relation.where(
- relation.table[self.class.primary_key].eq(quoted_id).and(
- relation.table[lock_col].eq(quoted_lock_value))
- ).arel.compile_update(
- arel_attributes_with_values_for_update(attribute_names),
- self.class.primary_key
- )
-
- affected_rows = self.class.connection.update stmt
unless affected_rows == 1
raise ActiveRecord::StaleObjectError.new(self, "update")
diff --git a/activerecord/test/cases/locking_test.rb b/activerecord/test/cases/locking_test.rb
index 5a4b1fb919..ee43f07dd7 100644
--- a/activerecord/test/cases/locking_test.rb
+++ b/activerecord/test/cases/locking_test.rb
@@ -33,8 +33,6 @@ class OptimisticLockingTest < ActiveRecord::TestCase
p1 = Person.find(1)
assert_equal 0, p1.lock_version
- Person.expects(:quote_value).with(0, Person.columns_hash[Person.locking_column]).returns('0').once
-
p1.first_name = 'anika2'
p1.save!