aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/counter_cache.rb
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2017-01-03 01:40:04 +0900
committerRyuta Kamizono <kamipo@gmail.com>2017-01-03 01:40:04 +0900
commitb177427d977b21cb18d2eca688539565e8970324 (patch)
treecde6f525b99605e8e20902f9356163ec3de99e25 /activerecord/lib/active_record/counter_cache.rb
parent4a36d81385bb78064fd3ebe0b35c9430017f7971 (diff)
downloadrails-b177427d977b21cb18d2eca688539565e8970324.tar.gz
rails-b177427d977b21cb18d2eca688539565e8970324.tar.bz2
rails-b177427d977b21cb18d2eca688539565e8970324.zip
Fix update counters of multiple records with touch: true
Currently does not work the following example in the doc: ```ruby # For the Posts with id of 10 and 15, increment the comment_count by 1 # and update the updated_at value for each counter. Post.update_counters [10, 15], comment_count: 1, touch: true # Executes the following SQL: # UPDATE posts # SET comment_count = COALESCE(comment_count, 0) + 1, # `updated_at` = '2016-10-13T09:59:23-05:00' # WHERE id IN (10, 15) ```
Diffstat (limited to 'activerecord/lib/active_record/counter_cache.rb')
-rw-r--r--activerecord/lib/active_record/counter_cache.rb2
1 files changed, 1 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/counter_cache.rb b/activerecord/lib/active_record/counter_cache.rb
index c654d4703a..f4ee008a12 100644
--- a/activerecord/lib/active_record/counter_cache.rb
+++ b/activerecord/lib/active_record/counter_cache.rb
@@ -105,7 +105,7 @@ module ActiveRecord
end
if touch
- object = find(id)
+ object = find(id.is_a?(Array) ? id.first : id)
updates << object.class.send(:sanitize_sql_for_assignment, touch_updates(object, touch))
end