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