# Order / line items problem

**URL:** <https://www.ruby-forum.com/t/order-line-items-problem/47767>\
**Category:** Rails\
**Created:** [November 13, 2005, 4:11pm UTC](https://www.ruby-forum.com/t/order-line-items-problem/47767 "2005-11-13T16:11:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sales](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58956e/32.png) [@sales](https://www.ruby-forum.com/u/sales)\
**Post date:** [November 13, 2005, 4:11pm UTC](https://www.ruby-forum.com/t/order-line-items-problem/47767/1 "2005-11-13T16:11:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sales](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58956e/32.png) [@sales](https://www.ruby-forum.com/u/sales)\
**Post date:** [November 13, 2005, 6:53pm UTC](https://www.ruby-forum.com/t/order-line-items-problem/47767/2 "2005-11-13T18:53:05Z")

</div>

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