aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorMarcel Molina <marcel@vernix.org>2007-05-06 05:08:05 +0000
committerMarcel Molina <marcel@vernix.org>2007-05-06 05:08:05 +0000
commit15dc567e0fffb2b71d41185364ff5ffb505ec61f (patch)
tree88ecde9e8e02dd63b8696af467e340b7649e4a68 /activerecord
parent5bd35705cae2e465b2fe2b2038bb409b63b78438 (diff)
downloadrails-15dc567e0fffb2b71d41185364ff5ffb505ec61f.tar.gz
rails-15dc567e0fffb2b71d41185364ff5ffb505ec61f.tar.bz2
rails-15dc567e0fffb2b71d41185364ff5ffb505ec61f.zip
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
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG2
-rwxr-xr-xactiverecord/lib/active_record/base.rb20
2 files changed, 16 insertions, 6 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index 5cd21b65f6..d05261ae94 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,6 +1,6 @@
*SVN*
-* Enhance documentation for decrement_counter. [fearoffish]
+* Enhance documentation for increment_counter and decrement_counter. [fearoffish]
* Provide brief introduction to what optimistic locking is. [fearoffish]
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 43879603e3..87bd064e49 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -555,11 +555,21 @@ module ActiveRecord #:nodoc:
update_all(updates, "#{connection.quote_column_name(primary_key)} = #{quote_value(id)}")
end
- # Increments the specified counter by one. So <tt>DiscussionBoard.increment_counter("post_count",
- # discussion_board_id)</tt> would increment the "post_count" counter on the board responding to discussion_board_id.
- # This is used for caching aggregate values, so that they don't need to be computed every time. Especially important
- # for looping over a collection where each element require a number of aggregate values. Like the DiscussionBoard
- # that needs to list both the number of posts and comments.
+ # Increment a number field by one, usually representing a count.
+ #
+ # This is used for caching aggregate values, so that they don't need to be computed every time.
+ # For example, a DiscussionBoard may cache post_count and comment_count otherwise every time the board is
+ # shown it would have to run a SQL query to find how many posts and comments there are.
+ #
+ # ==== Options
+ #
+ # +counter_name+ The name of the field that should be incremented
+ # +id+ The id of the object that should be incremented
+ #
+ # ==== Examples
+ #
+ # # Increment the post_count column for the record with an id of 5
+ # DiscussionBoard.increment_counter(:post_count, 5)
def increment_counter(counter_name, id)
update_counters(id, counter_name => 1)
end