Skip to content
This repository
Browse code

Also add documentation enhancements for increment_counter. Closes #8092

…. [fearoffish]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6684 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 15dc567e0fffb2b71d41185364ff5ffb505ec61f 1 parent 5bd3570
authored
2  activerecord/CHANGELOG
... ...
@@ -1,6 +1,6 @@
1 1
 *SVN*
2 2
 
3  
-* Enhance documentation for decrement_counter. [fearoffish]
  3
+* Enhance documentation for increment_counter and decrement_counter. [fearoffish]
4 4
 
5 5
 * Provide brief introduction to what optimistic locking is. [fearoffish]
6 6
 
20  activerecord/lib/active_record/base.rb
@@ -555,11 +555,21 @@ def update_counters(id, counters)
555 555
         update_all(updates, "#{connection.quote_column_name(primary_key)} = #{quote_value(id)}")
556 556
       end
557 557
 
558  
-      # Increments the specified counter by one. So <tt>DiscussionBoard.increment_counter("post_count",
559  
-      # discussion_board_id)</tt> would increment the "post_count" counter on the board responding to discussion_board_id.
560  
-      # This is used for caching aggregate values, so that they don't need to be computed every time. Especially important
561  
-      # for looping over a collection where each element require a number of aggregate values. Like the DiscussionBoard
562  
-      # that needs to list both the number of posts and comments.
  558
+      # Increment a number field by one, usually representing a count.
  559
+      #
  560
+      # This is used for caching aggregate values, so that they don't need to be computed every time. 
  561
+      # For example, a DiscussionBoard may cache post_count and comment_count otherwise every time the board is 
  562
+      # shown it would have to run a SQL query to find how many posts and comments there are.
  563
+      #
  564
+      # ==== Options
  565
+      #
  566
+      # +counter_name+  The name of the field that should be incremented
  567
+      # +id+            The id of the object that should be incremented
  568
+      #
  569
+      # ==== Examples
  570
+      #
  571
+      #   # Increment the post_count column for the record with an id of 5
  572
+      #   DiscussionBoard.increment_counter(:post_count, 5)
563 573
       def increment_counter(counter_name, id)
564 574
         update_counters(id, counter_name => 1)
565 575
       end

0 notes on commit 15dc567

Please sign in to comment.
Something went wrong with that request. Please try again.