From a3128665cf506c4762518df98aec3d63840e0698 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 2 Oct 2013 12:23:16 +1000 Subject: [PATCH] make it more idiomatic --- lib/freedom_patches/active_record_base.rb | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/lib/freedom_patches/active_record_base.rb b/lib/freedom_patches/active_record_base.rb index 96b2a1b232e..b8abe48a54a 100644 --- a/lib/freedom_patches/active_record_base.rb +++ b/lib/freedom_patches/active_record_base.rb @@ -12,17 +12,9 @@ class ActiveRecord::Base end # note: update_attributes still spins up a transaction this can cause contention - # this method performs the raw update sidestepping AR + # this method performs the raw update sidestepping the locking def update_columns(hash) - sql = "UPDATE #{ self.class.table_name } SET " - - sql << hash.map do |k,v| - "#{k} = :#{k}" - end.join(",") - - sql << " WHERE id = :id" - - exec_sql(sql, hash.merge(id: self.id)) + self.class.update_all(hash, self.class.primary_key => self.id) end def exec_sql(*args)