I just updated my mongoid to version 3.1.6, so that I could use the reset_counters method to keep track of my model relations. But just as I did before the gem update I still get this error:
undefined method `reset_counters' for Mongoid::Persistence::Atomic::Operation:Module
In my Gemfile I have this version:
gem 'mongoid', '3.1.6'
And Gemfile.lock states:
mongoid (3.1.6)
activemodel (~> 3.2)
moped (~> 1.4)
origin (~> 1.0)
tzinfo (~> 0.3.29)
Here is the model that should update the counters:
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
And here is the model where the counter field is:
class Operation
include Mongoid::Document
include Mongoid::Timestamps
field :presentations_count, type: Integer
has_many :presentations, :inverse_of => :operation, dependent: :destroy
end