24 lines
539 B
Ruby
Raw Permalink Normal View History

2024-10-27 21:42:45 +00:00
# Copyright (C) 2024 Manuel Bustillo
2024-08-11 16:29:10 +02:00
class Group < ApplicationRecord
validates :name, uniqueness: true
validates :name, :order, presence: true
2024-08-11 17:26:43 +02:00
has_many :children, class_name: 'Group', foreign_key: 'parent_id'
belongs_to :parent, class_name: 'Group', optional: true
before_create :set_color
2024-11-01 11:55:32 +01:00
scope :roots, -> { where(parent_id: nil) }
has_many :guests
private
def set_color
2024-11-04 23:39:44 +01:00
new_color = "##{SecureRandom.hex(3)}".paint
new_color = new_color.lighten(30) if new_color.dark?
self.color = new_color
end
2024-08-11 16:29:10 +02:00
end