I’m designing a database for a new CMS and having some trouble structuring tables for files and images.
Current design is to have tables with file info:
files:name,filename,extension,lang,sizeimages:name,filename,exstension,alt
Above them are tables for specific types named: product_files, article_files.
They have fields like (for product and images): id, image_id, product_id, position.
These tables are there because it can happen that different products have same images.
The thing is, I’m repeating those middle tables for every use case (2 for products, 2 for articles, etc.).
I was thinking of combining them in one table like:
items_imageswith columns:table,table_id,image_id,position
Is that a good way to go? Or should I leave it as is? To my knowledge I can’t set foreign keys on a table like that connecting it to tables of products or articles.
Edit:
It seems I wasn’t very clear about the problem. I don’t know how to best display it here so I’ll explain the picture (https://i.stack.imgur.com/wwUjM.png):
Just ignore the lines.
Top row are tables with actual file info. Documents, images and videos respectively.
Middle row are six tables grouped into three and each group connected to their table (products and articles). What I would like to do is make only three out of those six but still keep them connected to both products and articles at the same time. Maybe the solution is some 4th table but I don’t know.
You can use a table structure like :
id, image_id, pointer_id, position, type
where type will tell if it’s a product, article etc.