From 0cdb49818de7dd60748b00efc59c7c0ebdc11938 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Sat, 6 Apr 2019 17:45:44 +0100 Subject: [PATCH] Remove distinct from enterprise.ready_for_checkout scope Adapt use of enterprise scope not_ready_for_checkout to rails 4 by adding enterprises table alias to selected field id --- app/controllers/spree/admin/base_controller_decorator.rb | 2 +- app/models/enterprise.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/spree/admin/base_controller_decorator.rb b/app/controllers/spree/admin/base_controller_decorator.rb index 1d5d6e476a..6bdd57f0e8 100644 --- a/app/controllers/spree/admin/base_controller_decorator.rb +++ b/app/controllers/spree/admin/base_controller_decorator.rb @@ -52,7 +52,7 @@ Spree::Admin::BaseController.class_eval do def active_distributors_not_ready_for_checkout ocs = OrderCycle.managed_by(spree_current_user).active distributors = ocs.map(&:distributors).flatten.uniq - Enterprise.where('id IN (?)', distributors).not_ready_for_checkout + Enterprise.where('enterprises.id IN (?)', distributors).not_ready_for_checkout end def active_distributors_not_ready_for_checkout_message(distributors) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 3908650eb8..ac9252e389 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -111,14 +111,14 @@ class Enterprise < ActiveRecord::Base joins(:shipping_methods). joins(:payment_methods). merge(Spree::PaymentMethod.available). - select('DISTINCT enterprises.id') + select('enterprises.id') } scope :not_ready_for_checkout, lambda { # When ready_for_checkout is empty, return all rows when there are no enterprises ready for # checkout. ready_enterprises = Enterprise.ready_for_checkout if ready_enterprises.present? - where("id NOT IN (?)", ready_enterprises) + where("enterprises.id NOT IN (?)", ready_enterprises) else where("TRUE") end