2015-11-08 97 views
0

我有3种不同的型号正确的ActiveRecord的造型

BidOrderPrinter

class Printer < ActiveRecord::Base 
    has_many :bids 
end 

class Order < ActiveRecord::Base 
    belongs_to :user 
    has_many :bids 
end 

class Bid < ActiveRecord::Base 
    belongs_to :printer 
end 

我希望能够看到所有他们出价的上一个打印机的订单,但我目前的结构我不能做到这一点。它会像@printer.bids.orders

这怎么能做到这一点?我是否必须更改订单才能有belongs_to Printerhas_many: bids through orders?沿着这些线路的东西?

+0

在轨导找的has_many通过 –

回答

1

你将不得不宣告打印机是这样的:

class Printer < ActiveRecord::Base 
    has_many :bids 
    has_many :orders, through: :bids 
end 

这应该工作