Files
openfoodnetwork/app/models/spree/state.rb
cyrillefr 37814c46e5 Fix cop RedundantPresenceValidationOnBelongs
- presence: true is redundant since Rails 5.0 BUT applies
  with new default config of
  belongs_to_required_by_default to true
  Lots of files with belongs_to_required_by_default = false
  (backward compatibility)
  So: deleting this setting implies to adding optional: true
  on belongs_to relations where there is no explicit check for presence.
  And also to delete redundant presence: true
  The implicit becomes the explicit and vice versa
- updated toto list
2024-04-15 19:32:23 +02:00

22 lines
391 B
Ruby

# frozen_string_literal: true
module Spree
class State < ApplicationRecord
belongs_to :country, class_name: 'Spree::Country'
validates :name, presence: true
def self.find_all_by_name_or_abbr(name_or_abbr)
where('name = ? OR abbr = ?', name_or_abbr, name_or_abbr)
end
def <=>(other)
name <=> other.name
end
def to_s
name
end
end
end