Reputation: 1060
I have 3 different Models
Bid
Order
Printer
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
I would like to be able to view all of a printers orders they have bidded on, but with my current structure I cannot do it. it would be something like @printer.bids.orders
How can accomplish this? Would I have to change Order to have belongs_to Printer
, or has_many: bids through orders
? Something along those lines?
Upvotes: 0
Views: 32
Reputation: 11931
You would have to declare printer like this:
class Printer < ActiveRecord::Base
has_many :bids
has_many :orders, through: :bids
end
This should work
Upvotes: 1