Files
openfoodnetwork/app/models/inventory_item.rb
cyrillefr 9ae064a24f Fix RedundantPresenceValidationOnBelongs on some files
- presence: true is redundant since Rails 5.0 BUT applies
   with new default config of
   belongs_to_required_by_default to true
   Lots of files with belongs_to_required_by_default = false
   (backward compatibility)
   So: deleting this setting implies to adding optional: true
 - added 'NOT NULL' constraints so model constraints match
   with contraints on DB tables.
 - updated the todo
2024-04-22 17:36:47 +02:00

14 lines
427 B
Ruby

# frozen_string_literal: true
class InventoryItem < ApplicationRecord
belongs_to :enterprise
belongs_to :variant, class_name: "Spree::Variant"
validates :variant_id, uniqueness: { scope: :enterprise_id }
validates :visible,
inclusion: { in: [true, false], message: I18n.t(:inventory_item_visibility_error) }
scope :visible, -> { where(visible: true) }
scope :hidden, -> { where(visible: false) }
end