MySQL Database Design Problem Commodity Picture and Commodity Association Problem

  mysql, question


The Relationship between Commodity Pictures and Commodities

For example, if you release a commodity, there are many pictures of the commodity, how do these pictures relate to the commodity and how do you design the database?

My thoughts

GoodsTables,FileTables,good_fileAssociation Table

good_fileThere areIdgoods_idfile_id

If added firstGoodsTo increase againFileThat’s no problem, but if it’s being releasedGoodsAt the same time, addFileThis time becauseGoodsNot yet submitted, not yetgoods_id, then how to deal with?good_fileIn the association tablegoods_idHow?

Is my design thinking wrong?

I later thought, addFileWhen, if you don’t knowgoods_idThen putgoods_idSet toZeroWait for submissionGoodsAt the time of the updategood_fileIn the association tablegoods_idForZeroYes, but it is still wrong to think about it. If someone is releasing the product at this time, it will be wrong, or he uploaded itFileI haven’t submitted it yetGoodsThe browser was closed and an error occurred.

Want to want to go, don’t know how to deal with, help, general mall product release, how pictures associated with goods

First of all, I don’t think it is necessary to set up an intermediate association table. Because you’re just a simple table association,FileYesGoodsOne-on-one,GoodsYesFileIs one to many, then you canFileSettings in tablegoods_idField, inGoodsTable settingfile_idFields (goods can be left blank, depending on the frame you use) you can write like this:
AndGoodshit the targetIdThe field isnot null auto_incrementOf course, there is no problem in saving goods table fields.Filehit the targetgoods_idThere is no need to worry about the value.
I don’t know if LZ uses php, and what framework it uses. I usually use YI, which connects tables like Minutes.