I am in dilema regarding DB design, so I am expecting the forumians help here.
I have 3-4 tables(say categories, brands, products, etc.) and each table has images.
I would like to design db for images for all those tables.
Working on 1st: will be easier but it will violate the DRY principle.
Working on 2nd: will be a bit tricky on querying but it can be reused for different table just by using the combination of object_id & taxonomy fields.
I think I would personally prefer method 1. I’m not exactly sure why, it just seems to be more of a modular design to me. Maybe easier to extend, customize and modify down the road if necessary.
Also it would make your queries easier in general b/c you’re no longer having to worry about separating the images by category, they’re already separated.
I think the DRY method could be focused on having to repeat your query code (WHERE taxonomy=?) in EVERY image query you make. I do NOT think you are repeating yourself by having three similarly structured tables, the data in them will be completely different.
In either ways you have to query the tables exactly that number of times what the total tables are for images but only the table names will be different. So I would prefer the first method which is clear and would definitely be easy to extend and can be implemented Referential Integrity (RI) too. I don’t think you can implement easily RI with second method. So except increasing the number of tables in the database, there will not be anything wrong in first method as far as I know.