我的模型有2个外键属于同一型号。
Owner model
has_many :vehicles
end
车辆型号有2个字段owner_id和co_owner_id。
Vehicle model
belongs_to :owner, :foreign_key => 'owner_id'
end
如何定义co_owner_id字段的关系?所以我可以做一些像vehicle.co_owner.firstname
这样的事情答案 0 :(得分:0)
我不确定但不应该
belongs_to :co_owner, :foreign_key => 'co_owner_id', :class => 'owner'
做到了吗?