demarches-normaliennes/app/models/zone.rb
Christophe Robillard a504e82021 add zone label
2022-09-26 16:58:53 +02:00

19 lines
556 B
Ruby

# == Schema Information
#
# Table name: zones
#
# id :bigint not null, primary key
# acronym :string not null
# label :string
# created_at :datetime not null
# updated_at :datetime not null
#
class Zone < ApplicationRecord
validates :acronym, presence: true, uniqueness: true
has_many :labels, -> { order(designated_on: :desc) }, class_name: 'ZoneLabel', inverse_of: :zone
has_many :procedures, -> { order(published_at: :desc) }, inverse_of: :zone
def label
labels.first.name
end
end