Move select out of scope visible_for because it is breaking exchange_product queries and it's just not needed there. The only other use of this product's scope visible_for is the enterprise serializer so we add the select to it.

This commit is contained in:
Luis Ramos
2020-07-21 19:12:50 +01:00
parent 0fe9d2ac09
commit d4cfa0463f
2 changed files with 4 additions and 3 deletions

View File

@@ -63,8 +63,7 @@ Spree::Product.class_eval do
scope :visible_for, lambda { |enterprise|
joins('LEFT OUTER JOIN spree_variants AS o_spree_variants ON (o_spree_variants.product_id = spree_products.id)').
joins('LEFT OUTER JOIN inventory_items AS o_inventory_items ON (o_spree_variants.id = o_inventory_items.variant_id)').
where('o_inventory_items.enterprise_id = (?) AND visible = (?)', enterprise, true).
select('DISTINCT spree_products.*')
where('o_inventory_items.enterprise_id = (?) AND visible = (?)', enterprise, true)
}
# -- Scopes

View File

@@ -30,7 +30,9 @@ class Api::Admin::ForOrderCycle::EnterpriseSerializer < ActiveModel::Serializer
def products_scope
products_relation = object.supplied_products
if order_cycle.prefers_product_selection_from_coordinator_inventory_only?
products_relation = products_relation.visible_for(order_cycle.coordinator)
products_relation = products_relation.
visible_for(order_cycle.coordinator).
select('DISTINCT spree_products.*')
end
products_relation.order(:name)
end