Only delete related exchange variants if exchange is outgoing

This commit is contained in:
Matt-Yorkley
2023-05-22 11:09:29 +01:00
parent a8559e621f
commit 459ef5f0d1
2 changed files with 4 additions and 0 deletions

View File

@@ -122,6 +122,8 @@ class Exchange < ApplicationRecord
end
def delete_related_exchange_variants
return unless incoming?
ExchangeVariant.where(variant_id: variant_ids).
joins(:exchange).
where(exchanges: { order_cycle: order_cycle, incoming: false }).

View File

@@ -7,6 +7,8 @@ class ExchangeVariant < ApplicationRecord
after_destroy :delete_related_outgoing_variants
def delete_related_outgoing_variants
return unless exchange.incoming?
ExchangeVariant.where(variant_id: variant_id).
joins(:exchange).
where(exchanges: { order_cycle: exchange.order_cycle, incoming: false }).