Guys, I’m writing a small site for selling 4-5 types of products, it is possible to increase to 7 types in the future but no more, I don’t see the need to put opencarta combines. So the question is, create one table with all types and then create relative tables with properties (some products do not have fixed sizes, others have some items in kg) or just create a separate table for each type of product ?!
- oneFrom the point of code extension, it is better to put everything of the same type into one table, and break up the various (think over dynamics). In your version, with your confidence that no more than 7 products - make different tables and there will be no marks with links, etc. - Oleg Shleif
- I also inclined to this variant, I wanted to hear advice from experienced ones. Thank you - Cone Enoc
- Big or not big does not matter. There are potentially more than one goods - that's all, a table of goods is being made. We place the basic properties in the same table, additional ones in a separate one, most likely in the form of a key value. Otherwise, for the sake of 5 products you will have to write 5 blocks of code. add goods - add a block of code and at the same time review the rest. As a result, you will spend 5 times more time on development and especially on debugging. - Mike
1 answer
If you draw a diagram of objects of your application, you can immediately select four entities.
Abstractly:
- Product
- Stock (?)
- Sale
- The buyer (it depends on the logic of your application, it may not be needed)
Accordingly, the theory (and practice) suggests that each of these entities will require a separate (and unique for each) reference (it’s also a table in the database)
Let us dwell on the "product", since you have a question about it. Each item has some inalienable attributes, such as type, name, unit of sale (pieces / kilograms), unit price, unit size / weight, etc. It makes sense to store all these common attributes in the reference book (table) of goods.
If some types of goods have unique attributes, then they will require separate directories that are keyed to the entry in the product directory.
But how to organize reference books of unique attributes, there will be one table of the type "key" => "value", or several tables sharpened for specific attributes - it depends on the uniqueness of these very attributes and requirements to them.