2015-11-08 27 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 

這應該工作