Module: Mongoid::Relations::CounterCache

Extended by:
ActiveSupport::Concern
Included in:
Mongoid::Relations
Defined in:
lib/mongoid/relations/counter_cache.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#reset_counters(*counters) ⇒ Object

Reset the given counter using the .count() query from the db. This method is usuful in case that a counter got corrupted, or a new counter was added to the collection.

Examples:

Reset the given counter cache

post.reset_counters(:comments)

Parameters:

  • One (Symbol, Array)

    or more counter caches to reset

Since:

  • 4.0.0



17
18
19
# File 'lib/mongoid/relations/counter_cache.rb', line 17

def reset_counters(*counters)
  self.class.reset_counters(self, *counters)
end