Forum: Ruby on Rails order / line items problem

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
68c04209c9229e8126349e43c95998b5?d=identicon&s=25 sales (Guest)
on 2005-11-13 16:11
(Received via mailing list)
I'm trying to build a form that shows an order (from the orders table)
and
all of its line items (from the order_items table). I've defined the
models
like this:

class OrderItem < ActiveRecord::Base
belongs_to :order
end

class Order < ActiveRecord::Base
has_many :order_items
end

The problem is that the order object doesn't have any order items
associated
with it when I get to the edit form. I thought this association was
"automatic" based on the models. (no?)

I've tried

<% @order.order_items.each do |item| %>
<tr><td><%= item.item_id %></td></tr>
<% end %>

But this does not show anythingl.

I added a "debug(Order)" line on the form and I don't see any
"order_items"
in the object.

Richard
Eea3feaacbe44706164289d068d94828?d=identicon&s=25 petermichaux (Guest)
on 2005-11-13 18:53
(Received via mailing list)
Are there any order items associated with the order in the order_items
db
table?
This topic is locked and can not be replied to.