Reputation: 1132
I have some tables in the db which have either one image or several images associated with them. For instance:
# table 1
- id
- name
- created_at
# table 2
- id
- name
- created_at
Now each of these tables has either one or many images. A typical design would be like this:
# table 1
- id
- name
- image_path
- created_at
# table 2
- id
- name
- created_at
# images table
- id
- table_2_id
- image_path
- created_at
However, I happened to have several problems with design as the following:
So now I want to dealing with this problem as a multi-dimensional table for images is the right design choice and is it also going to be future proof?
# images
- id
- table_id
- table_name
- image_path
- created_at
Best regards. Thank you.
Upvotes: 3
Views: 2118
Reputation: 1833
You are looking at the problem in the reverse way. You need 1 table with all your images and each table that needs an image will have a link to the images tables
Upvotes: 4
Reputation: 601
You might consider doing a quick install of a popular open source CMS like WordPress or Drupal and add a few images to see how they accomplish this. Many CMS may have thought through some issues you have not considered.
Upvotes: -1