1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-01 12:24:28 +01:00
fab-manager/app/models/product_category.rb

19 lines
601 B
Ruby
Raw Normal View History

# frozen_string_literal: true
# Category is a first-level filter, used to categorize Products.
# It is mandatory to choose a Category when creating a Product.
class ProductCategory < ApplicationRecord
2022-08-20 18:47:15 +02:00
extend FriendlyId
friendly_id :name, use: :slugged
validates :name, :slug, presence: true
2022-09-19 19:31:43 +02:00
validates :slug, uniqueness: true
belongs_to :parent, class_name: 'ProductCategory'
2022-10-03 15:56:46 +02:00
has_many :children, class_name: 'ProductCategory', foreign_key: :parent_id, inverse_of: :parent, dependent: :nullify
2022-10-03 15:56:46 +02:00
has_many :products, dependent: :nullify
acts_as_list scope: :parent, top_of_list: 1
end