We are having a dilemma with modelling our data for a new application. The situation is somewhat complex; so I write down a simplified situation that is equivalent to our problem:
-
In a web app, the administrator creates a list of products; title, discription, linked to certain product categories; etc. So there is a Product entity
-
In the front-end, a user orders certain products; so there is an Order entity with a array of OrderLine entities associated with it; each OrderLine entitity has a Product associated with it.
-
After a few days, multiple Products are ordered. The administrator however needs to alter the price of a Product, or even deletes a Product, since it is no longer available.
-
In the database, there are still Orders associated with OrderLines, which are linked to Products. What happens when the adminstrator reviews the Orders in the database which where recorded before the product was altered in the database and that are associated to the product that was altered?
-
With avoiding redundancy as much as possible; on a database-level, how would you model such a case?
I’ve modelled
Products,OrdersandOrderItemsin a similar way; the only thing I have to add to @Neville K’s answer is that I’ve previously madeProductPricesdomain entities in their own right; adding a new price isn’t the same thing as adding a newProduct, after all. AProductPricehas a price, a currency and a start and end date; modelling prices like this also makes it possible to have group-specific prices or discounts for particular customers.