app/models/jobshop/rfq.rb in jobshop-0.0.163 vs app/models/jobshop/rfq.rb in jobshop-0.0.167
- old
+ new
@@ -2,21 +2,27 @@
module Jobshop
class RFQ < ApplicationRecord
self.primary_keys = %i[ organization_id rfq_id ]
- before_validation(on: :create) { self.rfq_id ||= SecureRandom.uuid }
+ after_initialize { self.rfq_id ||= SecureRandom.uuid if new_record? }
+ after_create { reload }
belongs_to :organization, inverse_of: :rfqs
- belongs_to :company, inverse_of: :rfqs, optional: true,
- foreign_key: %i[ organization_id company_id ]
+ belongs_to :customer, inverse_of: :rfqs, optional: true,
+ foreign_key: %i[ organization_id customer_id ]
+ belongs_to :requested_by, class_name: "Jobshop::Customer::Contact",
+ primary_key: %i[ organization_id customer_id contact_id ],
+ foreign_key: %i[ organization_id customer_id requested_by_id ],
+ optional: true
+
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)
+ def customer=(value)
+ customer_id = (Jobshop::Customer === value) ? value.customer_id : value
+ write_attribute(:customer_id, customer_id)
end
end
end