l4d.tools/app/models/overlay.rb
2026-01-18 17:42:32 +01:00

13 lines
618 B
Ruby

class Overlay < ApplicationRecord
belongs_to :user, optional: true
has_many :template_overlays, dependent: :destroy
has_many :server_templates, through: :template_overlays
validates :name, :overlay_type, :path, presence: true
validates :overlay_type, inclusion: { in: %w[system custom] }
validates :name, uniqueness: { scope: :user_id, message: "must be unique per user" }
scope :system_overlays, -> { where(overlay_type: "system").where(user_id: nil) }
scope :custom_overlays, -> { where(overlay_type: "custom") }
scope :for_user, ->(user) { where("user_id IS NULL OR user_id = ?", user.id) }
end