mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-28 21:07:16 +00:00
Rails 5 introduced this new class to confine application-specific monkey patches to our models only, and not leak into other libraries using ActiveRecord::Base. https://bigbinary.com/blog/application-record-in-rails-5
13 lines
461 B
Ruby
13 lines
461 B
Ruby
class InventoryItem < ApplicationRecord
|
|
belongs_to :enterprise
|
|
belongs_to :variant, class_name: "Spree::Variant"
|
|
|
|
validates :variant_id, uniqueness: { scope: :enterprise_id }
|
|
validates :enterprise, presence: true
|
|
validates :variant, presence: true
|
|
validates :visible, inclusion: { in: [true, false], message: I18n.t(:inventory_item_visibility_error) }
|
|
|
|
scope :visible, -> { where(visible: true) }
|
|
scope :hidden, -> { where(visible: false) }
|
|
end
|