2022-07-22 18:48:28 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Product is a model for the merchandise hold information of product in store
|
2022-07-13 15:06:46 +02:00
|
|
|
class Product < ApplicationRecord
|
|
|
|
belongs_to :product_category
|
2022-07-22 18:48:28 +02:00
|
|
|
|
|
|
|
has_and_belongs_to_many :machines
|
|
|
|
|
2022-08-02 19:47:56 +02:00
|
|
|
has_many :product_files, as: :viewable, dependent: :destroy
|
|
|
|
accepts_nested_attributes_for :product_files, allow_destroy: true, reject_if: :all_blank
|
|
|
|
|
|
|
|
has_many :product_images, as: :viewable, dependent: :destroy
|
|
|
|
accepts_nested_attributes_for :product_images, allow_destroy: true, reject_if: :all_blank
|
|
|
|
|
2022-07-22 18:48:28 +02:00
|
|
|
validates_numericality_of :amount, greater_than: 0, allow_nil: true
|
2022-07-25 10:26:01 +02:00
|
|
|
|
|
|
|
scope :active, -> { where(is_active: true) }
|
2022-07-13 15:06:46 +02:00
|
|
|
end
|