mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-29 06:21:16 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7dfe62a1c7 | ||
|
|
d264fa75e5 |
@@ -30,17 +30,19 @@ module OrderManagement
|
|||||||
other_permitted_producer_ids = EnterpriseRelationship.joins(:parent)
|
other_permitted_producer_ids = EnterpriseRelationship.joins(:parent)
|
||||||
.permitting(distributor.id).with_permission(:add_to_order_cycle)
|
.permitting(distributor.id).with_permission(:add_to_order_cycle)
|
||||||
.merge(Enterprise.is_primary_producer)
|
.merge(Enterprise.is_primary_producer)
|
||||||
.pluck(:parent_id)
|
.select(:parent_id)
|
||||||
|
|
||||||
# Append to the potentially gigantic array instead of using union, which creates a new array
|
Enterprise.where(id: distributor.id)
|
||||||
# The db IN statement won't care if there's a duplicate.
|
.select(:id)
|
||||||
other_permitted_producer_ids << distributor.id
|
.or(Enterprise.where(id: other_permitted_producer_ids))
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.outgoing_exchange_variant_ids(distributor)
|
def self.outgoing_exchange_variant_ids(distributor)
|
||||||
ExchangeVariant.select("DISTINCT exchange_variants.variant_id").joins(:exchange)
|
# DISTINCT is not required here since this subquery is used within an IN clause,
|
||||||
|
# where duplicate values do not impact the result.
|
||||||
|
ExchangeVariant.joins(:exchange)
|
||||||
.where(exchanges: { incoming: false, receiver_id: distributor.id })
|
.where(exchanges: { incoming: false, receiver_id: distributor.id })
|
||||||
.pluck(:variant_id)
|
.select(:variant_id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user