3 years ago

Populating lookup tables

Posted 3 years ago by TimeSocks


I have a site set up to sell my photographic prints. The photos are in categories and are available in a number of sizes, so I have a photos, categories and sizes table, joined by a category_photo and photo_size table.

Up to now I have been adding new photos to the site using PHPMyAdmin, but manually updating three tables is a bit of a pain, so I am building a little backend to make it quicker. I can add a new photo to the photos table easily enough, but when it comes to populating the lookup tables for category and size I am running into a problem with the table names.

Here is my code for populating the category_photo table:

foreach($request->category as $category)
            $cat_photo = new Category_Photo;
            $cat_photo->photo_id = $photo->id;
            $cat_photo->category_id = $category;

However, when I run this, I get the error:

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'db.category__photos' doesn't exist (SQL: insert into `category__photos` (`photo_id`, `category_id`) values (50, 1))

It is looking for a table called category__photos rather than category_photo. How can I rectify this? Or is there a better way to achieve what I'm trying to do?

Please sign in or create an account to participate in this conversation.