0
I’m doing academic work on comics, in this case I’m developing a database for a food distributor. I am in doubt as to how I can count the amount of sales that a seller has made in order to calculate the commission value. In addition, I created an entity for QUANTITY, how can I know the quantity of a product in an order occurrence?
But in case an order has several different products, if I put quantity as order attribute I will be limiting the quantity of all products and not only one?
– João Vitor Lumertz
In this case, you have an order relationship with multiple products and one product in multiple orders (Many to Many). When we have this situation, it is necessary to create a table that relates the order to the product, you can call it Pedidoproduct. There will be the product id and the order id (references to the order and product tables), which creates this relationship between these entities! You will create a record in this table for each product contained in the order. If you want, I will add this explanation in the reply.
– Giuliana Bezerra
Will I merge entities then? In that case the quantity of one product does not interfere with another?
– João Vitor Lumertz
You will create a new entity called Productopedido, maintaining the entities Product and Order, that is, it is not a merger, it is the creation of a new entity. The Quantity entity you remove, as it will exist as a property of the Request entity, just as you created the "total value" and "code". In the new entity Productopedido you will point to Product and Order, because it will have the id_product and id_request properties, each note being a relationship 1 to n.
– Giuliana Bezerra
Productopedido will be related to Order and Product?
– João Vitor Lumertz
That’s right. It allows you to have several products related to an order.
– Giuliana Bezerra
What are the attributes of the Produced entity?
– João Vitor Lumertz
Just a code identifier? I understand what you are talking about, but I am in doubt of how this entity works.
– João Vitor Lumertz
This entity will only have the product id and order id, so it is called Productopedido. It simply lists products with their respective orders.
– Giuliana Bezerra