-
Notifications
You must be signed in to change notification settings - Fork 1.4k
MONGOID-5189 Proper order of *_save callbacks #5083
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
ea53b5b
to
44d3779
Compare
8ed80e3
to
4915e15
Compare
lib/mongoid/interceptable.rb
Outdated
@@ -37,6 +37,9 @@ module Interceptable | |||
define_model_callbacks :build, :find, :initialize, :touch, only: :after | |||
define_model_callbacks :create, :destroy, :save, :update, :upsert | |||
|
|||
# @api private | |||
define_model_callbacks :save_relations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be save_associations
please and when the PR is ready for review, can this declaration also have a note added to it explaining its purpose (e.g. "This callback is used internally by Mongoid to save association targets for referenced associations after the parent model is saved", if I understood its purpose correctly).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe there can be even a better name. Now it is confusing we set it up, it is now like this:
klass.after_save_relations save_method, unless: :autosaved?
# or
klass.after_save_associations save_method, unless: :autosaved?
In reality the save_method
will be executed not after associations are saved. It will be called after the parent is saved, and actually saves associations. That's why I started with internal_save
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would save_parent
be a better choice? Then
klass.after_save_parent save_method, unless: :autosaved?
@@ -321,6 +321,8 @@ | |||
end | |||
|
|||
it 'applies the persistence options when saving the child' do | |||
skip 'https://jira.mongodb.org/browse/MONGOID-5190' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does pending
work here? If so the test would self-indicate when the functionality is repaired.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM if this is ready for review.
* master: Remove remaining encoding declarations (mongodb#5088) Add a more descriptive error when spec load fails (mongodb#5066) MONGOID-5191 Proper order for after_create callback (mongodb#5087) MONGOID-5189 Proper order of *_save callbacks (mongodb#5083) MONGOID-5098 Standardize/improve Range queries -- .where(field: 1..3) (mongodb#5025)
No description provided.