module ActiveRecord::CounterCache::ClassMethods

def update_counters(id, counters)

# WHERE id IN (10, 15)
# `updated_at` = '2016-10-13T09:59:23-05:00'
# SET comments_count = COALESCE(comments_count, 0) + 1,
# UPDATE posts
# Executes the following SQL:
Post.update_counters [10, 15], comments_count: 1, touch: true
# and update the updated_at value for each counter.
# For the Posts with id of 10 and 15, increment the comments_count by 1

# WHERE id IN (10, 15)
# SET comments_count = COALESCE(comments_count, 0) + 1
# UPDATE posts
# Executes the following SQL:
Post.update_counters [10, 15], comments_count: 1
# For the Posts with id of 10 and 15, increment the comments_count by 1

# WHERE id = 5
# actions_count = COALESCE(actions_count, 0) + 1
# SET comments_count = COALESCE(comments_count, 0) - 1,
# UPDATE posts
# Executes the following SQL:
Post.update_counters 5, comments_count: -1, actions_count: 1
# increment the actions_count by 1
# For the Post with id of 5, decrement the comments_count by 1, and

==== Examples

attributes.
If attribute names are passed, they are updated along with updated_at/on
* :touch option - Touch timestamp columns when updating.
to update as keys and the amount to update the field by as values.
* +counters+ - A Hash containing the names of the fields
* +id+ - The id of the object you wish to update a counter on or an array of ids.

==== Parameters

given by the corresponding value:
with the given ID, altering the given hash of counters by the amount
be useful on its own. It simply does a direct SQL update for the record
used by #increment_counter and #decrement_counter, but which may also
A generic "counter updater" implementation, intended primarily to be
def update_counters(id, counters)
  id = [id] if composite_primary_key? && id.is_a?(Array) && !id[0].is_a?(Array)
  unscoped.where!(primary_key => id).update_counters(counters)
end