Я только что обновил свой монгоид до версии 3.1.6, чтобы использовать reset_counters, чтобы отслеживать отношения моей модели. Но так же, как и до обновления драгоценного камня, я все еще получаю эту ошибку:
undefined method `reset_counters' for Mongoid::Persistence::Atomic::Operation:Module
В моем Gemfile у меня есть эта версия:
gem 'mongoid', '3.1.6'
И Gemfile.lock заявляет:
mongoid (3.1.6)
  activemodel (~> 3.2)
  moped (~> 1.4)
  origin (~> 1.0)
  tzinfo (~> 0.3.29)
Вот модель, которая должна обновлять счетчики:
class Presentation
  include Mongoid::Document
  include Mongoid::Timestamps
  belongs_to :operation, :inverse_of => :presentations, :counter_cache => true
  after_save :update_counter
  def update_counter
    self.operation_id_change.each do |e|
      Operation.reset_counters(e, :presentations) unless e.nil?
    end
  end
end
А вот модель, где поле счетчика:
class Operation
  include Mongoid::Document
  include Mongoid::Timestamps
  field :presentations_count, type: Integer
  has_many :presentations, :inverse_of => :operation, dependent: :destroy
end