1

In my application, I have many things that use images in different ways. For example, a product may have a logo and many screenshots, a user can have a profile image, and a company can have a logo.

I could use two different strategies a flexible tables or many tables.

Flexible tables would look like:

Images

  • id
  • relation_id
  • related_table
  • file_name

Image Meta

  • id
  • image_id
  • key
  • value

Many tables could look like:

Product Logos

  • id
  • file_name
  • product_id

Screenshots

  • id
  • filename
  • product_id
  • display_position

Profile Images

  • id
  • filename
  • user_id

etc.

So I'd like to know where is the balance between flexibility and normalization? or is there something I'm missing?

Thanks.

1

In term of performance, I believe that both cases would have the same result. Of course, it all depends on whether you make the right use of the indexes and relationships. But taking into account that the above care has already been taken, I would put, in a global view, three layers:

  1. Main tables: product, user and company
  2. Connection table
  3. Table of images

So I think this is more like your first choice where "Images" would be the connection table between the main tables and the images and "Image Meta" would be the table of images itself.

In this way, the main tables can even relate to the same image, avoiding duplication of image.

I just think that the "file_name" field should be in the "Images Meta" table and not in the connection table "Images".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.