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 _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Are there any order items associated with the order in the order_items db table? On 11/13/05, Richard Williams <sales-9yA49x/h1pUsV2N9l4h3zg@public.gmane.org> wrote:> > 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 > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Yes, there are two rows in the order_items for the order in question. Richard> > ---------- Forwarded message ---------- > From: Peter Michaux <petermichaux-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > Date: Sun, 13 Nov 2005 09:52:27 -0800 > Subject: Re: [Rails] order / line items problem > Are there any order items associated with the order in the order_items db > table? > > > > On 11/13/05, Richard Williams <sales-9yA49x/h1pUsV2N9l4h3zg@public.gmane.org> wrote: > > 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 > > > >