-
-
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
[RFC] Rename order.update! to order.recalculate #2072
Conversation
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.
Yes! Thanks 🙏🏼
core/app/models/spree/order.rb
Outdated
updater.update | ||
end | ||
|
||
alias_method :update!, :recalculate |
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.
Why this alias?
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.
Mistake. Fixed
f3b6b57
to
a1dc526
Compare
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.
<3 John. This is amazing.
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 agree that we should rename this method (also in Adjustment
and Shipment
). Thanks!
I am also on board with this. |
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.
A CHANGELOG entry would be welcome.
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.
Nice, that's a great way to do the deprecation
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.
Ditto on the CHANGELOG entry but I really like this!
|
Thanks for the feedback everyone. This was a lot less contentious than I expected. Merging now. As the 2.3 branch has been forked, this will be in our future 2.4.0 release. |
After update! => recalculate rename. ref: - solidusio#1689 - solidusio#2072
I expect this to be contentious, and it definitely introduces some work for users upgrading, which I'm always cautious of.
ActiveRecord::Base
has anupdate!(attributes)
which as of Rails 4.0 is the recommended way to update the attributes on a model. The PR introducing it describes the olderupdate_attributes!
as "soft-deprecated".Because we've overridden
update!
, we can't use that method to update the the attributes on order (asupdate!
does for every other model), and have to useupdate_attributes!
.This isn't great because Rails devs (as well as documentation) are going to expect
update!
to work and might not even be aware ofupdate_attributes!
. This is doubly confusing because we have access to ActiveRecord'sorder.update
, and one really expects that to do approximately the same thing as the!
version.This PR adds
Order#recalculate
, which does exactly whatOrder#update!
did, invoking theOrderUpdater
.Order#update!
will now, if given attributes, will behave like AR'supdate!
. If given no attributes it will emit a deprecation warning and callrecalculate
.If we decide to do this, we should probably do the same for
Adjustment#update!
andShipment#update!