Merge pull request #1406 from jordan-brough/add-order-payment-inverse-of #3
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.
Add
inverse_of
to order.paymentsCherry picked from Solidus to fix https://www.pivotaltracker.com/story/show/134172587
Without this reverse association, an order object can have different payment objects in memory. When one version of the object is updated, the other is not, leading to unexpected behaviors.
In the case presented specifically in this story, the initial credit card payment is put in the
invalid
state byinvalidate_old_payments
when the new Apple Pay payment is created. However, without the reverse association, when the state machine advances the order fromconfirm
tocomplete
and beginsprocess_payments!
, theorder.payments.map(&:state)
shows["checkout", "checkout"]
showing the in-memory version oforder.payments
is stale.Jordan fixed this and many other in-memory association problems in Solidus v1.4. We're back porting this one now because it's causing acute problems.