14 lines
345 B
Ruby

# Copyright (C) 2024 Manuel Bustillo
class Group < ApplicationRecord
validates :name, uniqueness: true
validates :name, :order, presence: true
has_many :children, class_name: 'Group', foreign_key: 'parent_id'
belongs_to :parent, class_name: 'Group', optional: true
scope :roots, -> { where(parent_id: nil) }
has_many :guests
end