Prevention of double calls in callbacks #5518
Replies: 3 comments 4 replies
-
To add the modern-day code, I believe this is an effect of: |
Beta Was this translation helpful? Give feedback.
-
We discovered that this is partially fixed in Mongoid 8 with the introduction of |
Beta Was this translation helpful? Give feedback.
-
Hi @Greg-Myers-SB, thank you for starting this discussion. I've moved the details you've shared to https://jira.mongodb.org/browse/MONGOID-5542 as this may be a bug, and if it was already addressed in Mongoid 8 we can use this ticket to track the backporting. |
Beta Was this translation helpful? Give feedback.
-
Hi Mongoid team,
I was looking at the PR that originally added the run_callbacks method and I noticed it mentions:
#1058
However mongoid does now include multi-level nested documents so that later got resolved :)
The reason I was reading this code is because I noticed that if you have a grandparent relation and you use around_save on the grandchild and cascade callbacks, it will call the around_save twice.
Does anyone have any thoughts on preventing the hooks being fired multiple times per document so that I could do something like a side-effect in a callback?
Beta Was this translation helpful? Give feedback.
All reactions