…then you’ll be able to say: @the_order_line.order
So, if you want to go the other way: @the_order.order_line
… you need the association in your Order class so that it knows. It
doesn’t look it the other models for associations that refer to it.
Order model
has_many :order_lines
If you already have this, then you might try checking order, then
orderlines, then product, then name. Maybe you’re missing an
association
there somewhere. If that doesn’t work, some detail about what you’re
actually getting would help.
One other thing that helps me is the Rails console. You can
interactively
make an Order, test its lines, etc all without the continually
save/refresh
cycle of doing it in a web browser.
For what it’s worth I haven’t written much rails/ruby, I mostly lurk
here
… but that said,
Order has many OrderLines has many Products seems like your model and
from
what you’ve described, you’re missing that final association …
I guess I’d also think OrderLines would have order_id, product_id and
quantity … while Products would have unit cost, description, etc …
Right, what Hank said, almost.
You’ve got the
Order model
has_many :order_lines
You know that it’s working because you can get to the product_id, which
is
on the order line. Since you can’t get to the product, you know that
the
OrderLine model doesn’t know about the product.
OrderLine model
belongs_to :product
You want belongs_to because the id for the product is in the order_lines
table. Once you add that to the OrderLines model, you should be able to
access a product from an order detail.
That’s a handy link for the examples Wes … I might have to actually
start
writing some of this stuff just for fun so I can better grok the syntax
more
naturally.