Fix PG::UndefinedTable errors

The logic of #includes has changed slightly in Rails 4.2 and now usually needs the #references method as well.

PG::UndefinedTable:
     #   ERROR:  missing FROM-clause entry for table "enterprises"
     #   LINE 1: SELECT "spree_users".* FROM "spree_users" WHERE (enterprises...
     #                                                            ^
     #   ./spec/models/spree/user_spec.rb:125:in `block (4 levels) in <top (required)>'
This commit is contained in:
Matt-Yorkley
2020-11-06 17:11:42 +00:00
parent a5472d6b64
commit 49081e171e

View File

@@ -60,7 +60,10 @@ module OpenFoodNetwork
def filter_to_supplier(orders)
if params[:supplier_id].to_i > 0
orders.select do |order|
order.line_items.includes(:product).references(:product).where("spree_products.supplier_id = ?", params[:supplier_id].to_i).count > 0
order.line_items.includes(:product)
.where("spree_products.supplier_id = ?", params[:supplier_id].to_i)
.references(:product)
.count > 0
end
else
orders