I have a table images and album_images. Is the album_images table unnecessary?

38
July 12, 2018, at 01:10 AM

I've created a website where a user can upload a single image or a whole album of images and 3 views - one for displaying all single images, one for displaying all albums (just the title image of each album) and one for displaying all album_images that have album_id of the album.

My tables are as follows:

Table: images
Columns: id, name, description, user_id, file_name, upvotes, downvotes, views
Table: albums
Columns: id, name, description, user_id, thumbnail, upvotes, downvotes, views
Table: album_images
Columns: id, album_id, file_name

A couple of reasons why I created a second table that would contain images:

1 - I wanted to have my home page display all single images without displaying any of the album images. My reasoning was that an image from an album might not make any sense if seen without the rest of the images. I know believe that this problem could be bypassed by creating an is_album_image column that would be false if it is a single image and true if it is an album image. This way I could still only show single images on my home page whilst removing the second images table.

2 - The album_images table doesn't have many of the images columns like name and description because the album images don't need those, the album itself will have that information, the only information I need about the album images is the id of the album they are in and their file_name. I believe that this means I'd have to add more columns to the images table and have some of the old columns be nullable if I wanna merge the two tables.

I would really love to hear opinions on whether my album_images table is unnecessary and if I should try to merge them. Of course I'd have to change some stuff in my controllers but I don't mind as long as it looks and works better.

Answer 1

No, just need a One to Many Relationship

Table: images
Columns: id, name, description, user_id, album_id, file_name, upvotes, downvotes, views
Table: albums
Columns: id, name, description, user_id, thumbnail, upvotes, downvotes, views

You can define your relations for Eloquent in your album, image and user model.

Answer 2

I can't tell you that is necessary, unless you're trying to save the path of the image, for example.

READ ALSO
Can you get images from a PHP upload?

Can you get images from a PHP upload?

So I have a page containing PHP that will take multiple images, then save and display them

49
if smiliar foreach then add together Laravel 5.2

if smiliar foreach then add together Laravel 5.2

i want to add the values if they were same and similar

42
which is faster? echo “” or close php for printign HTML

which is faster? echo “” or close php for printign HTML

in my wordpress special Theme functionphp file i have alot of functions that contain some Html inside php codes

56
Not beautiful json array PHP [duplicate]

Not beautiful json array PHP [duplicate]

This question already has an answer here:

67