1
0
Fork 0
This repository has been archived on 2023-03-27. You can view files and clone it, but cannot push or open issues or pull requests.
lpr-partynest/app/models/relation_transition.rb

37 lines
787 B
Ruby

# frozen_string_literal: true
class RelationTransition < ApplicationRecord
FORMAT_RE = /\A[^[:space:]]+(.*[^[:space:]]+)?\z/.freeze
################
# Associations #
################
belongs_to :from_status,
class_name: 'RelationStatus',
inverse_of: :transitions,
optional: true
belongs_to :to_status,
class_name: 'RelationStatus'
###############
# Validations #
###############
validates :name,
presence: true,
length: { in: 1..255 },
format: FORMAT_RE,
uniqueness: true
validate :statuses_are_not_equal
private
def statuses_are_not_equal
return if from_status.nil? || to_status.nil? || from_status != to_status
errors.add :to_status
end
end