Question about database design for product orders

Published 10 months ago by PaulDiamant

I'm working on an ecommerce platform, and have a products table, orders table and orders_products table. Should I save the price of the single item in the orders_products table or fetch it every time the user goes to their cart and after they make a purchase?

10 months ago (151,880 XP)

@PaulDiamant It is better to save prices in the orders_products , because the price can change, and the user will be surprised.


Imo @Dry7 is right, the correct table for the price of a product is the crosstable between orders and products because it reflects the state of the information at the time the order is made.

Another thing: in Laravel crosstables are usually named by the singular names of the related tables in alphabetical order. In your specific case the laravel-esque name of your crosstable would be order_product.

Please sign in or create an account to participate in this conversation.