rails routes - 模型关系

时间:2011-11-07 03:44:11

标签: ruby-on-rails activerecord

我的模型有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

这样的事情

1 个答案:

答案 0 :(得分:0)

我不确定但不应该

belongs_to :co_owner, :foreign_key => 'co_owner_id', :class => 'owner'

做到了吗?