2 / 3
Mar 2024

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?

16 days later
6 months later

I just ran into this. Between Mongoid 7.x and 8 the order of callbacks has changed in a way that status_changed now returns false. Use saved_change_to_status? instead.

I looked for all after_update and after_save in my code and made it return unless xyz_changed? || saved_change_to_xyz?