mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Only delete related exchange variants if exchange is outgoing
This commit is contained in:
@@ -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 }).
|
||||
|
||||
@@ -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 }).
|
||||
|
||||
Reference in New Issue
Block a user