From 1eba17f048e06a2806df4b58c37d31af557e8d21 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Tue, 18 Feb 2020 15:13:44 +0000 Subject: [PATCH] Make select column explicit to avoid too many columns sql error --- app/models/enterprise.rb | 4 ++-- app/models/enterprise_fee.rb | 2 +- app/models/enterprise_relationship.rb | 2 +- app/models/exchange.rb | 2 +- app/models/spree/order_decorator.rb | 6 ++++-- app/models/spree/payment_method_decorator.rb | 2 +- app/models/spree/shipping_method_decorator.rb | 2 +- app/models/spree/variant_decorator.rb | 2 +- lib/open_food_network/order_and_distributor_report.rb | 2 +- 9 files changed, 13 insertions(+), 11 deletions(-) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 1deee05a40..8211a17157 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -321,7 +321,7 @@ class Enterprise < ActiveRecord::Base def distributed_taxons Spree::Taxon. joins(:products). - where('spree_products.id IN (?)', Spree::Product.in_distributor(self)). + where('spree_products.id IN (?)', Spree::Product.in_distributor(self).select(&:id)). select('DISTINCT spree_taxons.*') end @@ -337,7 +337,7 @@ class Enterprise < ActiveRecord::Base def supplied_taxons Spree::Taxon. joins(:products). - where('spree_products.id IN (?)', Spree::Product.in_supplier(self)). + where('spree_products.id IN (?)', Spree::Product.in_supplier(self).select(&:id)). select('DISTINCT spree_taxons.*') end diff --git a/app/models/enterprise_fee.rb b/app/models/enterprise_fee.rb index 64c362b0fe..f26fee44eb 100644 --- a/app/models/enterprise_fee.rb +++ b/app/models/enterprise_fee.rb @@ -27,7 +27,7 @@ class EnterpriseFee < ActiveRecord::Base if user.has_spree_role?('admin') scoped else - where('enterprise_id IN (?)', user.enterprises) + where('enterprise_id IN (?)', user.enterprises.select(&:id)) end } diff --git a/app/models/enterprise_relationship.rb b/app/models/enterprise_relationship.rb index 6acd672f2f..e0b9c62c03 100644 --- a/app/models/enterprise_relationship.rb +++ b/app/models/enterprise_relationship.rb @@ -22,7 +22,7 @@ class EnterpriseRelationship < ActiveRecord::Base } scope :involving_enterprises, ->(enterprises) { - where('parent_id IN (?) OR child_id IN (?)', enterprises, enterprises) + where('parent_id IN (?) OR child_id IN (?)', enterprises.select(&:id), enterprises.select(&:id)) } scope :permitting, ->(enterprise_ids) { where('child_id IN (?)', enterprise_ids) } diff --git a/app/models/exchange.rb b/app/models/exchange.rb index ce28a7255d..4531ec042b 100644 --- a/app/models/exchange.rb +++ b/app/models/exchange.rb @@ -49,7 +49,7 @@ class Exchange < ActiveRecord::Base } scope :with_product, lambda { |product| joins(:exchange_variants). - where('exchange_variants.variant_id IN (?)', product.variants_including_master) + where('exchange_variants.variant_id IN (?)', product.variants_including_master.select(&:id)) } scope :by_enterprise_name, -> { joins('INNER JOIN enterprises AS sender ON (sender.id = exchanges.sender_id)'). diff --git a/app/models/spree/order_decorator.rb b/app/models/spree/order_decorator.rb index 28d487d6fd..f0085d25e6 100644 --- a/app/models/spree/order_decorator.rb +++ b/app/models/spree/order_decorator.rb @@ -56,7 +56,9 @@ Spree::Order.class_eval do # Find orders that are distributed by the user or have products supplied by the user # WARNING: This only filters orders, you'll need to filter line items separately using LineItem.managed_by with_line_items_variants_and_products_outer. - where('spree_orders.distributor_id IN (?) OR spree_products.supplier_id IN (?)', user.enterprises, user.enterprises). + where('spree_orders.distributor_id IN (?) OR spree_products.supplier_id IN (?)', + user.enterprises.select(&:id), + user.enterprises.select(&:id)). select('DISTINCT spree_orders.*') end } @@ -65,7 +67,7 @@ Spree::Order.class_eval do if user.has_spree_role?('admin') scoped else - where('spree_orders.distributor_id IN (?)', user.enterprises) + where('spree_orders.distributor_id IN (?)', user.enterprises.select(&:id)) end } diff --git a/app/models/spree/payment_method_decorator.rb b/app/models/spree/payment_method_decorator.rb index f32944fdcb..6b917fcb4e 100644 --- a/app/models/spree/payment_method_decorator.rb +++ b/app/models/spree/payment_method_decorator.rb @@ -20,7 +20,7 @@ Spree::PaymentMethod.class_eval do scoped else joins(:distributors). - where('distributors_payment_methods.distributor_id IN (?)', user.enterprises). + where('distributors_payment_methods.distributor_id IN (?)', user.enterprises.select(&:id)). select('DISTINCT spree_payment_methods.*') end } diff --git a/app/models/spree/shipping_method_decorator.rb b/app/models/spree/shipping_method_decorator.rb index 813c947f38..ba7836899d 100644 --- a/app/models/spree/shipping_method_decorator.rb +++ b/app/models/spree/shipping_method_decorator.rb @@ -15,7 +15,7 @@ Spree::ShippingMethod.class_eval do scoped else joins(:distributors). - where('distributors_shipping_methods.distributor_id IN (?)', user.enterprises). + where('distributors_shipping_methods.distributor_id IN (?)', user.enterprises.select(&:id)). select('DISTINCT spree_shipping_methods.*') end } diff --git a/app/models/spree/variant_decorator.rb b/app/models/spree/variant_decorator.rb index 84750cbe94..566394d946 100644 --- a/app/models/spree/variant_decorator.rb +++ b/app/models/spree/variant_decorator.rb @@ -49,7 +49,7 @@ Spree::Variant.class_eval do } scope :for_distribution, lambda { |order_cycle, distributor| - where('spree_variants.id IN (?)', order_cycle.variants_distributed_by(distributor)) + where('spree_variants.id IN (?)', order_cycle.variants_distributed_by(distributor).select(&:id)) } scope :visible_for, lambda { |enterprise| diff --git a/lib/open_food_network/order_and_distributor_report.rb b/lib/open_food_network/order_and_distributor_report.rb index b32ab803cc..64f46f41d1 100644 --- a/lib/open_food_network/order_and_distributor_report.rb +++ b/lib/open_food_network/order_and_distributor_report.rb @@ -68,7 +68,7 @@ module OpenFoodNetwork else orders. where('spree_orders.id NOT IN (?)', - @permissions.editable_orders) + @permissions.editable_orders.select(&:id)) end end