Reputation: 1060
I have four models
Bid
Order
User
Printer
currently I cannot access the order through anything except User
.
I would like to be able to do something of the sort bid.order
but have yet to figure out the correct association. Any thoughts?
class Bid < ActiveRecord::Base
belongs_to :printer
end
class Order < ActiveRecord::Base
belongs_to :user
has_many :bids
end
class Printer < ActiveRecord::Base
has_many :orders, through: :bids
has_many :bids
end
class User < ActiveRecord::Base
has_many :orders
end
Upvotes: 0
Views: 43
Reputation: 26071
Both models must know about the relationship so you need to state that in the Bid model
class Bid < ActiveRecord::Base
belongs_to :printer
belongs_to :order
end
Upvotes: 4