-
-
Notifications
You must be signed in to change notification settings - Fork 20
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
🐞🔨 Marketplace
: DeliveryAreas
cannot be Removed when in use
#2015
🐞🔨 Marketplace
: DeliveryAreas
cannot be Removed when in use
#2015
Conversation
# rubocop:disable Rails/SkipsModelValidations | ||
delivery_area.carts.update_all(delivery_area_id: nil) | ||
# rubocop:enable Rails/SkipsModelValidations | ||
delivery_area.destroy |
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.
Might be worth wrapping these two lines in a transaction.
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.
ooo good point.
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.
Random thought: could we accomplish this with something like this on the Delivery Area model?
has_many :pre_checkout_carts, ...appropriate scopes go here..., dependent: :nullify
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.
Maybe? I forgot about dependent: :nullify
; but the test coverage should prove it out.
@@ -13,7 +13,7 @@ def create | |||
|
|||
when "checkout.session.completed" | |||
payment_intent = Stripe::PaymentIntent.retrieve(event.data.object.payment_intent, {api_key: marketplace.stripe_api_key}) | |||
order = marketplace.orders.find_by(id: payment_intent.transfer_group) | |||
order = Order.unscoped.find_by(id: payment_intent.transfer_group, marketplace:) |
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 don't love how this reads. It immediately makes me want to go and check why does this need to be unscoped and what does that mean. Does that mean that really this is a "cart_or_order"? Or should this be a "cart"? Or something else?
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.
This is a consequence of that default scope that I added; I'm going to revert that.
app/furniture/marketplace/order.rb
Outdated
@@ -1,6 +1,7 @@ | |||
class Marketplace | |||
class Order < Record | |||
self.table_name = "marketplace_orders" | |||
default_scope { where.not(status: :pre_checkout) } |
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 do we need a default scope here? How certain are we that this won't introduce yet another bug somewhere where an edge case isn't tested? (I'm not certain at all, personally.)
I'd rather we explicitly applied named scopes as needed, instead of having a default scope.
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.
Yea, this is a side effect of not having split the marketplace_carts
and marketplace_orders
tables out. I like putting it in a named scope!
OK, this should be a bit nicer. There's some other cleanup I want to do in another PR to: - Rip out the Turbo Streams (they don't seem useful) - Make the button say "Archive" when there are Orders
160f3ac
to
d600a0c
Compare
has_many :orders, inverse_of: :delivery_area | ||
has_many :carts, inverse_of: :delivery_area | ||
has_many :orders, -> { checked_out }, inverse_of: :delivery_area | ||
has_many :carts, inverse_of: :delivery_area, dependent: :nullify |
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.
Ah, and this works because Marketplace::Carts
has a default scope of :pre_checkout
, right? Nice
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, which is part of why I kinda-like the default scopes; but also I now have a ticket for the refactor: #2020
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, ship it!
This:
destroy
DeliveryAreas
with anOrder
Cart#delivery_area
onDeliveryAreas#destroy