-
Type: Improvement
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: Associations, Callbacks
-
None
I have a following setup:
class Album include Mongoid::Document include Mongoid::Timestamps embeds_many :photos, cascade_callbacks: true end class Photo include Mongoid::Document embedded_in :album mount_uploader :file, PhotoUploader after_save do PhotoWorker.perform_async(id) end end
.. now, because I need to process photos with some Sidekiq workers I have an after_save callback (in Photo) that starts the worker.
album.save
However, the issue is that if the .save is called on the parent model, the embedded documents callbacks will all be called first, and the very 'save' command (for mongoid) will be sent only afterwards in the usual flow of parent document.
I have some debug prints setup and it can be seen that the callbacks run as follows
"photo before_save" "photo after_save" "album before_save" # runs the save call "album after_save"
.. so you can see that in this case one is being told that a document has been saved when it is not, and so, in some cases, Sidekiq workers cannot find the documents.
I'm guessing that this might not be the intended behaviour.
- is depended on by
-
MONGOID-3446 created_at nil for embedded documents
- Closed
- is duplicated by
-
MONGOID-4411 Update on root document does not invoke before_save callback correctly in embedded docs with cascade_callbacks: true
- Closed
- is related to
-
MONGOID-4271 Embedded relation not set when after_save is called on embedded doc
- Backlog
-
MONGOID-3648 Inconsistent behaviour for embedded objects callbacks
- Closed
- links to