Files
openfoodnetwork/app/models/spree/state.rb
cyrillefr 43005672a9 Fix RedundantPresenceValidationOnBelongs on other files
- 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
 - added 'NOT NULL' constraints so model constraints match
   with contraints on DB tables.
 - corresponding migration files to match AR Models &
   DB tables
 - rake tasks to check corrupt data (ie: NULL/nil in id fields)
 - updated the todo
2024-04-24 15:19:17 +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