[RFC] Rename order.update! to order.recalculate #2072
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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!