2022-07-11 19:17:36 +02:00
|
|
|
# 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
|
|
|
|
|
2022-07-11 19:17:36 +02:00
|
|
|
validates :name, :slug, presence: true
|
|
|
|
|
|
|
|
belongs_to :parent, class_name: 'ProductCategory'
|
|
|
|
has_many :children, class_name: 'ProductCategory', foreign_key: :parent_id
|
|
|
|
|
2022-07-25 10:26:01 +02:00
|
|
|
has_many :products
|
|
|
|
|
2022-07-20 11:54:46 +02:00
|
|
|
acts_as_list scope: :parent, top_of_list: 0
|
2022-07-11 19:17:36 +02:00
|
|
|
end
|