From 00f811645a10d57d7d95586b04ca98e9306f045f Mon Sep 17 00:00:00 2001
From: Du Peng <gnepud@gmail.com>
Date: Mon, 25 Jul 2022 10:26:01 +0200
Subject: [PATCH] add products relation in product's category

---
 app/models/product.rb          | 2 ++
 app/models/product_category.rb | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/app/models/product.rb b/app/models/product.rb
index 29d0e1697..d4c26abc2 100644
--- a/app/models/product.rb
+++ b/app/models/product.rb
@@ -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
diff --git a/app/models/product_category.rb b/app/models/product_category.rb
index 8feb8afda..fdc492f83 100644
--- a/app/models/product_category.rb
+++ b/app/models/product_category.rb
@@ -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