diff options
author | Sean Griffin <sean@thoughtbot.com> | 2014-12-26 17:30:58 -0700 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2014-12-26 17:30:58 -0700 |
commit | 0520e6559ef377de841c2fb2345835732756f451 (patch) | |
tree | 3097c49bd8eab08669209ecb28aee88db47e9450 /activerecord/lib | |
parent | 796574c92c7409ebcb200a99e90763779fe6e931 (diff) | |
download | rails-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
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/counter_cache.rb | 7 |
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 |