Skip to content

Commit

Permalink
Remove distinct from enterprise.ready_for_checkout scope
Browse files Browse the repository at this point in the history
Adapt use of enterprise scope not_ready_for_checkout to rails 4 by adding enterprises table alias to selected field id
  • Loading branch information
luisramos0 committed Apr 7, 2019
1 parent ff67eee commit f64e2cd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/controllers/spree/admin/base_controller_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def unauthorized
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)
Expand Down
4 changes: 2 additions & 2 deletions app/models/enterprise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ 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, ActiveRecord generates the SQL:
# id NOT IN (NULL)
# I would have expected this to return all rows, but instead it returns none. To
# work around this, we use the "OR ?=0" clause to return all rows when there are
# no enterprises ready for checkout.
where('id NOT IN (?) OR ?=0',
where('enterprises.id NOT IN (?) OR ?=0',
Enterprise.ready_for_checkout,
Enterprise.ready_for_checkout.count)
}
Expand Down

0 comments on commit f64e2cd

Please sign in to comment.