# 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