small medium large xlarge

Generic-user-small
30 Aug 2008, 05:43
Tan YL (19 posts)

Hi,

i’ve read chapter 10 but i still don’t get how to add a line item to a normal database. The example is for sessions.

I want to add a line item that has a user foreign key which is attached to a product foreign key. What code do i add to the controller and form to get this to work?

Samr_small_pragsmall
30 Aug 2008, 12:11
Sam Ruby (634 posts)

I’m not sure what you mean by “a user foreign key which is attached to a product foreign key”.

In the Chapter 10 definition of line item, a line item has two foreign keys: order and product. These relationships can be established from either side: rails takes care of the rest.

Inside the add_line_items_from_cart method in the Order class you will find this:

line_items << li

Inside the from_cart_item method in the LineItem class you will find this:

li.product = cart_item.product

Chapter 18 contains much more detail. If you like, you can skip ahead.

Generic-user-small
31 Aug 2008, 15:54
Tan YL (19 posts)

thanks

You must be logged in to comment