diff options
author | Sean Griffin <sean@thoughtbot.com> | 2014-12-26 17:17:01 -0700 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2014-12-26 17:17:01 -0700 |
commit | 796574c92c7409ebcb200a99e90763779fe6e931 (patch) | |
tree | 93c52637cfe0c5118807b920e40c97bd11980819 | |
parent | a61a85683a0214eb96937cec3b3fef82d2f164ec (diff) | |
download | rails-796574c92c7409ebcb200a99e90763779fe6e931.tar.gz rails-796574c92c7409ebcb200a99e90763779fe6e931.tar.bz2 rails-796574c92c7409ebcb200a99e90763779fe6e931.zip |
We don't need additional type casting for locking updates
Part of the larger refactoring to remove type casting from Arel. We can
inform it that we already have the right type by wrapping the value in
an `Arel::Nodes::Quoted`. This commit can be reverted when we have
removed type casting from Arel in Rail 5.1
-rw-r--r-- | activerecord/lib/active_record/locking/optimistic.rb | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/locking/optimistic.rb b/activerecord/lib/active_record/locking/optimistic.rb index ced694ba9a..eb0bcff740 100644 --- a/activerecord/lib/active_record/locking/optimistic.rb +++ b/activerecord/lib/active_record/locking/optimistic.rb @@ -80,10 +80,18 @@ module ActiveRecord begin relation = self.class.unscoped - stmt = relation.where( - relation.table[self.class.primary_key].eq(id).and( - relation.table[lock_col].eq(self.class.quote_value(previous_lock_value, column_for_attribute(lock_col))) + # 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), ) + ) + 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 |