Permalink
Browse files

Use COALESCE in update_counters docs to reflect the implementation

  • Loading branch information...
1 parent 7d0b69d commit 0dfb8ff347b3ca72dda24ccb1edc75b46df98668 @carlosantoniodasilva carlosantoniodasilva committed Aug 18, 2010
Showing with 3 additions and 3 deletions.
  1. +3 −3 activerecord/lib/active_record/counter_cache.rb
@@ -56,15 +56,15 @@ def reset_counters(id, *counters)
# Post.update_counters 5, :comment_count => -1, :action_count => 1
# # Executes the following SQL:
# # UPDATE posts
- # # SET comment_count = comment_count - 1,
- # # action_count = action_count + 1
+ # # SET comment_count = COALESCE(comment_count, 0) - 1,
+ # # action_count = COALESCE(action_count, 0) + 1
# # WHERE id = 5
#
# # For the Posts with id of 10 and 15, increment the comment_count by 1
# Post.update_counters [10, 15], :comment_count => 1
# # Executes the following SQL:
# # UPDATE posts
- # # SET comment_count = comment_count + 1,
+ # # SET comment_count = COALESCE(comment_count, 0) + 1,
# # WHERE id IN (10, 15)
def update_counters(id, counters)
updates = counters.map do |counter_name, value|

0 comments on commit 0dfb8ff

Please sign in to comment.