Product

posko · app/models/product.rb · ruby · MIT
unclassified, database, pos

Product model with variants, categories, and inventory associations.

# Source: https://github.com/neume/posko | License: MIT | Copyright 2017-2018 Joseph Nelson Valeros
# Provided via justclaw.it.com; keep this notice with the code.
class Product < ApplicationRecord
  enum product_type: [:regular, :composite, :component]
  enum product_status: [:active]
  attr_accessor :price

  has_many :variants, dependent: :destroy
  has_many :invoice_lines, dependent: :destroy
  has_many :components, through: :variants
  has_many :classifications, dependent: :destroy
  has_many :categories, through: :classifications
  has_many :option_types, dependent: :destroy

  belongs_to :default_variant, class_name: 'Variant', optional: true
  belongs_to :account
  belongs_to :created_by, class_name: 'User'

  accepts_nested_attributes_for :variants

  validates :title, presence: t

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key