时间:2010-07-23 21:27:43

标签: ruby-on-rails activerecord

1 个答案:

答案 0 :(得分:0)

我相信答案可能是:

class Order < ActiveRecord::Base
    set_primary_key(:order_id)
    belongs_to :invoice, :foreign_key => :order_id
end

class WorkOrder < ActiveRecord::Base
    set_primary_key(:order_id)
    belongs_to :invoice, :foreign_key => :order_id
end

class Invoice < ActiveRecord::Base
    set_primary_key(:order_id)
    has_one :work_order
    has_one :order
end

虽然我不确定你的主键也可以是外键(我也是Rails的新手)