Make select column explicit to avoid too many columns sql error

This commit is contained in:
Luis Ramos
2020-02-18 15:13:44 +00:00
parent 18c165e893
commit 1eba17f048
9 changed files with 13 additions and 11 deletions

View File

@@ -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

View File

@@ -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
}

View File

@@ -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) }

View File

@@ -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)').

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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|

View File

@@ -68,7 +68,7 @@ module OpenFoodNetwork
else
orders.
where('spree_orders.id NOT IN (?)',
@permissions.editable_orders)
@permissions.editable_orders.select(&:id))
end
end