aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2019-05-12 10:54:48 +0900
committerGitHub <noreply@github.com>2019-05-12 10:54:48 +0900
commitb1c917ee2fdaa452aeb52904db0d254d85285380 (patch)
treea5d99da40f1bd1e9a7eca9a76178c70fdc56caf4
parent317543ce7baba16dc06dd970b4343b1d1495a56b (diff)
parent19eb85d1bd1990cb6dfb2ff52315e1ed892ff2ce (diff)
downloadrails-b1c917ee2fdaa452aeb52904db0d254d85285380.tar.gz
rails-b1c917ee2fdaa452aeb52904db0d254d85285380.tar.bz2
rails-b1c917ee2fdaa452aeb52904db0d254d85285380.zip
Merge pull request #36073 from itsWill/document_update_counters_on_relation
document update_counters on relation [ci skip]
-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 = {}