1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-30 19:52:20 +01:00

add products relation in product's category

This commit is contained in:
Du Peng 2022-07-25 10:26:01 +02:00
parent 5e1436eda4
commit 00f811645a
2 changed files with 4 additions and 0 deletions

View File

@ -7,4 +7,6 @@ class Product < ApplicationRecord
has_and_belongs_to_many :machines
validates_numericality_of :amount, greater_than: 0, allow_nil: true
scope :active, -> { where(is_active: true) }
end

View File

@ -8,5 +8,7 @@ class ProductCategory < ApplicationRecord
belongs_to :parent, class_name: 'ProductCategory'
has_many :children, class_name: 'ProductCategory', foreign_key: :parent_id
has_many :products
acts_as_list scope: :parent, top_of_list: 0
end