views:

41

answers:

2

Hi,

How would you store sales ?

I though about storing a serialized array which contains the products ordered vs a sale_product table with a foreign key referencing products ordered.

What are you thoughts about this ? Any experience with one of these ?

Ty

+1  A: 

It depends on what you are trying to optimize. A sale_product table is a much better way to go if you want flexibility and ability to do complex queries. The other way could be suitable for a few scenarios where performance of one type of query is really important.

If you are just starting, I would consider a normalized design first, because I would consider the other design premature optimization. When designing a database model, I like to think of what kind of operations the database will need to support (both frontend and reporting), and then design the model.

Artem
+1  A: 

Sales are not necessarily identical to Orders. An order may not result in a sale if the product can unexpectedly not be delivered, if payment bounces, etc.

Peladao