# 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 before_create :set_color scope :roots, -> { where(parent_id: nil) } has_many :guests private def set_color self.color = "##{SecureRandom.hex(3)}" end end