Sha256: 14866b3d5cd3fce1b64e0f56b99c89312e63406e8833a6b45c39d607a6d13b47

Contents?: true

Size: 748 Bytes

Versions: 1

Compression:

Stored size: 748 Bytes

Contents

module Jobshop
  class Product < ApplicationRecord
    self.primary_keys = [ :organization_id, :product_id ]

    after_create do
      self.class.connection.clear_query_cache
      @attributes = self.class.unscoped {
        self.class.find_by!(organization: organization, name: name)
      }.instance_variable_get(:@attributes)
      @new_record = false
      self
    end

    belongs_to :organization, inverse_of: :products
    belongs_to :created_by, class_name: "Jobshop::User",
      foreign_key: [ :organization_id, :created_by_id ]
    has_one :routing_process, inverse_of: :product,
      foreign_key: [ :organization_id, :product_id ]
    has_many :routing_steps, through: :routing_process

    validates :name, presence: true
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jobshop-0.0.157 app/models/jobshop/product.rb