Files
openfoodnetwork/app/models/spree/country.rb
2023-10-06 10:58:49 +09:00

24 lines
444 B
Ruby

# frozen_string_literal: true
module Spree
class Country < ApplicationRecord
has_many :states, -> { order('name ASC') }, dependent: :destroy
validates :name, :iso_name, presence: true
def self.cached_find_by(attrs)
Rails.cache.fetch("countries/#{attrs.hash}", expires_in: 1.hour) do
find_by(attrs)
end
end
def <=>(other)
name <=> other.name
end
def to_s
name
end
end
end