Sha256: 6d2b631ecde6cd2658953c6cd1f8cfc61eaba06ddc3a7599cf5a37645923ae39

Contents?: true

Size: 625 Bytes

Versions: 1

Compression:

Stored size: 625 Bytes

Contents

# frozen_string_literals: true

module Jobshop
  class RFQ < ApplicationRecord
    self.primary_keys = %i[ organization_id rfq_id ]

    before_validation(on: :create) { self.rfq_id ||= SecureRandom.uuid }

    belongs_to :organization, inverse_of: :rfqs

    belongs_to :company, inverse_of: :rfqs, optional: true,
      foreign_key: %i[ organization_id company_id ]

    has_many :rfq_lines, inverse_of: :rfq,
      foreign_key: %i[ organization_id rfq_id ]

    def company=(value)
      company_id = (Jobshop::Company === value) ? value.company_id : value
      write_attribute(:company_id, company_id)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jobshop-0.0.163 app/models/jobshop/rfq.rb