aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/counter_cache.rb
diff options
context:
space:
mode:
authorKasper Timm Hansen <kaspth@gmail.com>2017-01-15 19:36:34 +0100
committerKasper Timm Hansen <kaspth@gmail.com>2017-01-15 19:36:34 +0100
commita0a1ede8c2eb6436571eae8778033162d1f9dcc3 (patch)
tree632bc7020c220c56fce87368fe8c83e8df57a699 /activerecord/lib/active_record/counter_cache.rb
parent1f2a283365cba1efd766adc2d0e38ea44ef31675 (diff)
downloadrails-a0a1ede8c2eb6436571eae8778033162d1f9dcc3.tar.gz
rails-a0a1ede8c2eb6436571eae8778033162d1f9dcc3.tar.bz2
rails-a0a1ede8c2eb6436571eae8778033162d1f9dcc3.zip
Don't guard against `touch: []`.
Closes #27683. Seeing a code sample that leads to what we're guarding against: ```ruby Topic.update_counters(1, replies_count: 1, touch: []) ``` It doesn't look like a case people would ever intentionally end up with. Thus we're better off sparing the conditional. Note: it could happen if a method returns an empty array that's then passed to `update_counters` and its touchy friends. But `[].presence` can fix that once people see their query blow up. [ Eugene Kenny & Kasper Timm Hansen ]
Diffstat (limited to 'activerecord/lib/active_record/counter_cache.rb')
-rw-r--r--activerecord/lib/active_record/counter_cache.rb3
1 files changed, 1 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/counter_cache.rb b/activerecord/lib/active_record/counter_cache.rb
index cbd71a3779..93b9371206 100644
--- a/activerecord/lib/active_record/counter_cache.rb
+++ b/activerecord/lib/active_record/counter_cache.rb
@@ -105,8 +105,7 @@ module ActiveRecord
end
if touch
- touch_updates = touch_updates(touch)
- updates << sanitize_sql_for_assignment(touch_updates) unless touch_updates.empty?
+ updates << sanitize_sql_for_assignment(touch_updates(touch))
end
unscoped.where(primary_key => id).update_all updates.join(", ")