-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Fixing product discard and classifications issue #3439
Fixing product discard and classifications issue #3439
Conversation
When removing a product via discard, it was destroying all classifications via delete_all, acts as list callbacks were not called leaving gaps in position.
@@ -25,7 +25,7 @@ class Product < Spree::Base | |||
variants_including_master.discard_all | |||
self.product_option_types = [] | |||
self.product_properties = [] | |||
self.classifications = [] | |||
self.classifications.destroy_all |
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.
Style/RedundantSelf: Redundant self detected.
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.
Great catch, I think we should use discard_all
instead. Also, in another PR I think it's a good idea to do the same with the rest of the associations in that block, if they are soft-deletable, right?
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.
Classifications is not discard'able, that's why I used destroy_all so act_as_list callbacks are executed.
I also had a look at the other relationships and the only one with callbacks is product properties but position is only used for sorting, it does not affect like in classifications
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.
You are right @softr8, the rest of associations should be handled in a different context, if needed. Thanks!
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.
👍
@@ -25,7 +25,7 @@ class Product < Spree::Base | |||
variants_including_master.discard_all | |||
self.product_option_types = [] | |||
self.product_properties = [] | |||
self.classifications = [] | |||
self.classifications.destroy_all |
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.
You are right @softr8, the rest of associations should be handled in a different context, if needed. Thanks!
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.
@softr8 thanks for the fix 👍
When removing a product via discard, it was destroying all
classifications via delete_all, acts as list callbacks were
not called leaving gaps in position.
Created this one instead of #3172
Checklist: