# frozen_string_literals: true module Jobshop class Customer::Category < ApplicationRecord self.primary_keys = %i[ organization_id category_id ] after_initialize { self.category_id ||= SecureRandom.uuid if new_record? } after_create { reload } belongs_to :organization, -> { readonly }, inverse_of: :customer_categories has_many :customers, inverse_of: :category, foreign_key: %i[ organization_id category_id ] validates :name, uniqueness: { case_insensitive: true, scope: :organization_id } end end