Method: Mongoid::Relations::CounterCache::ClassMethods#decrement_counter

Defined in:
lib/mongoid/relations/counter_cache.rb

#decrement_counter(counter_name, id) ⇒ Object

Decrement the counter name from the entries that match the id by one. This method is used on associations callbacks when counter_cache is enable

Examples:

Decrement comments counter

Post.decrement_counter(:comments_count, '50e0edd97c71c17ea9000001')

Since:

  • 3.1.0



74
75
76
# File 'lib/mongoid/relations/counter_cache.rb', line 74

def decrement_counter(counter_name, id)
  update_counters(id, counter_name.to_sym => -1)
end