This follows from this question (How can I have two columns in one table point to the same column in another with ActiveRecord?) but there is a slightly different nuance.
I have a model Order
, which has three columns that point to the same table Estimate
: estimate_id
, finalized_estimate_id
, cost_price_estimate_id
.
class Order < ApplicationRecord
belongs_to :estimate
belongs_to :finalized_estimate, class_name: "Estimate", optional: true
belongs_to :cost_price_estimate, class_name: "Estimate", optional: true
end
What would the estimate class look like? And secondly could an estimate know which column it is from? I.e. will/can an estimate model know it is a finalized_estimate
, cost_price_estimate
or just an estimate
?
(Estimate will always only have_one
order)