module ActiveRecord::CounterCache::ClassMethods

def decrement_counter(counter_name, id, by: 1, touch: nil)

DiscussionBoard.decrement_counter(:posts_count, 5, touch: true)
# and update the updated_at value.
# Decrement the posts_count column for the record with an id of 5

DiscussionBoard.decrement_counter(:posts_count, 5, by: 3)
by a specific amount.
# Decrement the posts_count column for the record with an id of 5

DiscussionBoard.decrement_counter(:posts_count, 5)
# Decrement the posts_count column for the record with an id of 5

==== Examples

touch that column or an array of symbols to touch just those ones.
Pass +true+ to touch +updated_at+ and/or +updated_on+. Pass a symbol to
* :touch - Touch timestamp columns when updating.
* :by - The amount by which to decrement the value. Defaults to +1+.
* +id+ - The id of the object that should be decremented or an array of ids.
* +counter_name+ - The name of the field that should be decremented.

==== Parameters

1 instead of increasing it.
This works the same as #increment_counter but reduces the column value by

Decrement a numeric field by one, via a direct SQL update.
def decrement_counter(counter_name, id, by: 1, touch: nil)
  update_counters(id, counter_name => -by, touch: touch)
end