aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorGuilherme Mansur <guilherme.mansur@shopify.com>2019-04-23 18:01:25 -0400
committerGuilherme Mansur <guilherme.mansur@shopify.com>2019-05-11 14:13:32 -0400
commit19eb85d1bd1990cb6dfb2ff52315e1ed892ff2ce (patch)
treebf21d1de04c36db9349b49026cbabad69741bf99 /activerecord/lib/active_record
parentdf35204ed190086ec95b308ac1764571344005a6 (diff)
downloadrails-19eb85d1bd1990cb6dfb2ff52315e1ed892ff2ce.tar.gz
rails-19eb85d1bd1990cb6dfb2ff52315e1ed892ff2ce.tar.bz2
rails-19eb85d1bd1990cb6dfb2ff52315e1ed892ff2ce.zip
document update_counters on relation [ci skip]
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/relation.rb14
1 files changed, 13 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb
index add95f6a0a..ea8f44752b 100644
--- a/activerecord/lib/active_record/relation.rb
+++ b/activerecord/lib/active_record/relation.rb
@@ -468,7 +468,19 @@ module ActiveRecord
end
end
- def update_counters(counters) # :nodoc:
+ # Updates the counters of the records in the current relation.
+ #
+ # === Parameters
+ #
+ # * +counter+ - A Hash containing the names of the fields to update as keys and the amount to update as values.
+ # * <tt>:touch</tt> option - Touch the timestamp columns when updating.
+ # * If attributes names are passed, they are updated along with update_at/on attributes.
+ #
+ # === Examples
+ #
+ # # For Posts by a given author increment the comment_count by 1.
+ # Post.where(author_id: author.id).update_counters(comment_count: 1)
+ def update_counters(counters)
touch = counters.delete(:touch)
updates = {}