aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2014-12-26 17:30:58 -0700
committerSean Griffin <sean@thoughtbot.com>2014-12-26 17:30:58 -0700
commit0520e6559ef377de841c2fb2345835732756f451 (patch)
tree3097c49bd8eab08669209ecb28aee88db47e9450
parent796574c92c7409ebcb200a99e90763779fe6e931 (diff)
downloadrails-0520e6559ef377de841c2fb2345835732756f451.tar.gz
rails-0520e6559ef377de841c2fb2345835732756f451.tar.bz2
rails-0520e6559ef377de841c2fb2345835732756f451.zip
Go through normal `update_all` logic when updating counter caches
Part of a larger refactoring to remove type casting behavior from Arel
-rw-r--r--activerecord/lib/active_record/counter_cache.rb7
1 files changed, 3 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/counter_cache.rb b/activerecord/lib/active_record/counter_cache.rb
index 101889638d..7d8e0a2063 100644
--- a/activerecord/lib/active_record/counter_cache.rb
+++ b/activerecord/lib/active_record/counter_cache.rb
@@ -37,10 +37,9 @@ module ActiveRecord
reflection = child_class._reflections.values.find { |e| e.belongs_to? && e.foreign_key.to_s == foreign_key && e.options[:counter_cache].present? }
counter_name = reflection.counter_cache_column
- stmt = unscoped.where(arel_table[primary_key].eq(object.id)).arel.compile_update({
- arel_table[counter_name] => object.send(counter_association).count(:all)
- }, primary_key)
- connection.update stmt
+ unscoped.where(primary_key => object.id).update_all(
+ counter_name => object.send(counter_association).count(:all)
+ )
end
return true
end