Eventually, I''d like to figure out for myself a catalog/shoppingcart
system in RoR. The catalog seems super-easy, so I''m pondering the cart
first- specifically the database schema.
Obviously, there''s the classic issue of hoping that you have many
customers, and hoping that they place many orders, to buy many products.
So, based on the discussion here:
http://www.frick-cpa.com/ss7/Theory_EX_Normalization.asp
I''d suppose, for Rails we''d need tables somewhat like the
following:
customers: id, address, city, state, zip, phone, email
orders: id, customer_id, created_on
products: id,name, description, price, category_id, image_path
categories: id,name
and then a join table (here''s where I get fuzzy):
orders_products: order_id, product_id, quantity
I would then create my model for order and product, and add:
has_and_belongs_to :product
and
has_and_belongs_to :order
respectively, yes?
and add:
has_many :orders
to the customers model?
>From here, I''m clueless :)
What I would ultimately like to produce is when the user checks out:
*a row is created in the customers table for them (easy)
*a row is added to the order table with their customer id to generate an
order_id
*multiple rows are added to the orders_products table, each having the
product_id, order_id and the quantity for each item in their cart
Could I use the scaffolding generator to get me started on this, or am I
on my own?
Of course, I''m not asking for anyone to write this for me, but any
pointers/roadmap for pulling it together would be a great help.