Skip to content

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

Merged
merged 8 commits into from
Sep 30, 2021

Conversation

comandeo
Copy link
Contributor

No description provided.

@comandeo comandeo marked this pull request as draft September 27, 2021 08:08
@comandeo comandeo force-pushed the 5189-around-after-save branch from ea53b5b to 44d3779 Compare September 27, 2021 09:51
@comandeo comandeo force-pushed the 5189-around-after-save branch from 8ed80e3 to 4915e15 Compare September 29, 2021 10:02
@comandeo comandeo marked this pull request as ready for review September 29, 2021 10:05
@@ -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
Copy link
Contributor

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).

Copy link
Contributor Author

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.

Copy link
Contributor

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'
Copy link
Contributor

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.

Copy link
Contributor

@p-mongo p-mongo left a 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.

@comandeo comandeo merged commit 8c1f40f into mongodb:master Sep 30, 2021
@comandeo comandeo deleted the 5189-around-after-save branch September 30, 2021 08:15
p-mongo pushed a commit to p-mongo/mongoid that referenced this pull request Oct 4, 2021
p-mongo pushed a commit to johnnyshields/mongoid that referenced this pull request Oct 5, 2021
* 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants