Order / line items problem


#1

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| %>

<%= item.item_id %> <% 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


#2

Are there any order items associated with the order in the order_items
db
table?