From b796822288152491f0f3557b78362ce8b14d30c9 Mon Sep 17 00:00:00 2001 From: lukaszreszke Date: Wed, 25 Sep 2024 14:16:59 +0200 Subject: [PATCH] Ignore stock level column of Product --- rails_application/app/models/product.rb | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/rails_application/app/models/product.rb b/rails_application/app/models/product.rb index ada3829b..dc685e1c 100644 --- a/rails_application/app/models/product.rb +++ b/rails_application/app/models/product.rb @@ -2,25 +2,20 @@ class Product < ApplicationRecord self.locking_column = :version + self.ignored_columns = %w[stock_level] validates :name, presence: true validates :price, numericality: { greater_than: 0 } validate :validate_vat_rate validates :sku, presence: true - has_one :product_catalog, class_name: "Inventory::ProductCatalog", foreign_key: :product_id + has_one :product_catalog, + class_name: "Inventory::ProductCatalog", + foreign_key: :product_id default_scope { where(latest: true) } - before_create :set_stock_level - - def set_stock_level - self.stock_level = 0 - end - def validate_vat_rate - unless vat_rate.is_a?(Numeric) - errors.add(:vat_rate, "is not a number") - end + errors.add(:vat_rate, "is not a number") unless vat_rate.is_a?(Numeric) end end