Forum: Ruby on Rails order / line items problem

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
sales (Guest)
on 2005-11-13 17:11
(Received via mailing list)
I'm trying to build a form that shows an order (from the orders table)
all of its line items (from the order_items table). I've defined the
like this:

class OrderItem < ActiveRecord::Base
belongs_to :order

class Order < ActiveRecord::Base
has_many :order_items

The problem is that the order object doesn't have any order items
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
in the object.

petermichaux (Guest)
on 2005-11-13 19:53
(Received via mailing list)
Are there any order items associated with the order in the order_items
This topic is locked and can not be replied to.