mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
- 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
22 lines
391 B
Ruby
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
|