Mongoid 8 callback

We are testing Mongoid 8.1.5 and are running into some issues with callback.

Essentially, we are trying to update all child models if a status changed in the parent model.

In Mongoid 7, we have this:

after_update :after_update_callback
def after_update_callback
  if self.status_changed?
    self.stores.update_all(company_status: self.status)
  end
end

However, that doesn’t work in Mongoid 8, the status_changed? returns false instead of true.

We also tried changing the callback from after_update to around_update, but we get this error:
Calling save! on Company resulted in a false return from a callback.

We also reviewed https://www.mongodb.com/docs/mongoid/current/release-notes/mongoid-8.0/#order-of-callback-invocation but it wasn’t helpful. Any ideas?

Hi @netwire,

To help us troubleshoot can you just share the parent/child model definitions.

I’m assuming to trigger the callbacks you just had something like:

company.status = "some new value"
company.save!