Fix deprecation warning in rails 6.0

Warning: Class level methods will no longer inherit scoping from create in Rails 6.1
This commit is contained in:
Luis Ramos
2021-05-10 21:03:24 +01:00
parent cbefa5f882
commit d308e20871
3 changed files with 4 additions and 3 deletions

View File

@@ -121,7 +121,7 @@ class Enterprise < ApplicationRecord
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.
ready_enterprises = Enterprise.default_scoped.ready_for_checkout.
except(:select).
select('DISTINCT enterprises.id')

View File

@@ -309,7 +309,7 @@ module Spree
record = true
while record
random = "H#{Array.new(11) { rand(9) }.join}"
record = self.class.find_by(number: random)
record = self.class.default_scoped.find_by(number: random)
end
self.number = random
end

View File

@@ -49,8 +49,9 @@ module Spree
# Do other links exist with this permalink?
other = self.class.
where("#{self.class.table_name}.#{field} LIKE ?", "#{permalink_value}%")
default_scoped.where("#{self.class.table_name}.#{field} LIKE ?", "#{permalink_value}%")
if other.any?
# Find the existing permalink with the highest number, and increment that number.
# (If none of the existing permalinks have a number, this will evaluate to 1.)
number = other.map { |o| o.__send__(field)[/-(\d+)$/, 1].to_i }.max + 1