Skip to content

Commit 05a45c1

Browse files
authored
Merge pull request rails#48082 from ybakos/ar_counter_cache_examples
Use pluralized counter names in the ActiveRecord `update_counters` method docs
2 parents 45ec165 + 6fe65ec commit 05a45c1

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

activerecord/lib/active_record/counter_cache.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,28 +87,28 @@ def reset_counters(id, *counters, touch: nil)
8787
#
8888
# ==== Examples
8989
#
90-
# # For the Post with id of 5, decrement the comment_count by 1, and
91-
# # increment the action_count by 1
92-
# Post.update_counters 5, comment_count: -1, action_count: 1
90+
# # For the Post with id of 5, decrement the comments_count by 1, and
91+
# # increment the actions_count by 1
92+
# Post.update_counters 5, comments_count: -1, actions_count: 1
9393
# # Executes the following SQL:
9494
# # UPDATE posts
95-
# # SET comment_count = COALESCE(comment_count, 0) - 1,
96-
# # action_count = COALESCE(action_count, 0) + 1
95+
# # SET comments_count = COALESCE(comments_count, 0) - 1,
96+
# # actions_count = COALESCE(actions_count, 0) + 1
9797
# # WHERE id = 5
9898
#
99-
# # For the Posts with id of 10 and 15, increment the comment_count by 1
100-
# Post.update_counters [10, 15], comment_count: 1
99+
# # For the Posts with id of 10 and 15, increment the comments_count by 1
100+
# Post.update_counters [10, 15], comments_count: 1
101101
# # Executes the following SQL:
102102
# # UPDATE posts
103-
# # SET comment_count = COALESCE(comment_count, 0) + 1
103+
# # SET comments_count = COALESCE(comments_count, 0) + 1
104104
# # WHERE id IN (10, 15)
105105
#
106-
# # For the Posts with id of 10 and 15, increment the comment_count by 1
106+
# # For the Posts with id of 10 and 15, increment the comments_count by 1
107107
# # and update the updated_at value for each counter.
108-
# Post.update_counters [10, 15], comment_count: 1, touch: true
108+
# Post.update_counters [10, 15], comments_count: 1, touch: true
109109
# # Executes the following SQL:
110110
# # UPDATE posts
111-
# # SET comment_count = COALESCE(comment_count, 0) + 1,
111+
# # SET comments_count = COALESCE(comments_count, 0) + 1,
112112
# # `updated_at` = '2016-10-13T09:59:23-05:00'
113113
# # WHERE id IN (10, 15)
114114
def update_counters(id, counters)

0 commit comments

Comments
 (0)