mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-25 20:46:48 +00:00
Rails 5 introduced this new class to confine application-specific monkey patches to our models only, and not leak into other libraries using ActiveRecord::Base. https://bigbinary.com/blog/application-record-in-rails-5
22 lines
401 B
Ruby
22 lines
401 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Spree
|
|
class State < ApplicationRecord
|
|
belongs_to :country, class_name: 'Spree::Country'
|
|
|
|
validates :country, :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
|