Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82803

Link Table is not being populated, what am I doing wrong?

$
0
0

I've been trying to figure this out for a while but can't seem to put my finger on it. I currently have a database structure as follows (with fake data):

-------------------    -----------------    -------------------
|     reviews     |    |    images     |    | reviews_images  |
-------------------    -----------------    -------------------
| id_rev |  name  |    | id_img | url  |    | rev_id | img_id |
-------------------    -----------------    -------------------
|   1    | Doom   |    |   1    | http |    |   2    |   1    |
|   2    | Doom 2 |    |   2    | http |    |   2    |   2    |
|   3    | Doom 3 |    |   3    | http |    |   2    |   3    |
-------------------    -----------------    -------------------

When I add a new record to the list it adds the records for both the reviews and the images table. For some strange reason the link table (reviews_images) does not get update and is left completely blank. Once the tables loads the new data I have the review data showing but with the blank spot where the image should be.

As the image table is being populated (and the file subsequently uploaded to the correct directory), I assume that the link table is working and doing its job during processing, but why it isn't during data injection I don't know. This is what I have for my server script (irrelevant parts left out):

Editor::inst($db, "reviews", "id_reviews")
    ->fields(
        Field::inst("reviews.id_reviews"),
        Field::inst("reviews.name")                 -> validator("Validate::notEmpty"),
        Field::inst("reviews_images.reviews_id")    -> options("reviews", "id_reviews", "id_reviews"),
        Field::inst("reviews_images.images_id")     -> options("images", "id_images", "id_images"),
        Field::inst("images.id_images")             -> setFormatter("Format::ifEmpty", null)
                                                    -> upload(Upload::inst($_SERVER["DOCUMENT_ROOT"]."/uploads/__ID__.__EXTN__")
                                                        -> db("images", "id_images", array(
                                                            "filename"      => Upload::DB_FILE_NAME,
                                                            "filesize"      => Upload::DB_FILE_SIZE,
                                                            "web_path"      => Upload::DB_WEB_PATH,
                                                            "system_path"   => Upload::DB_SYSTEM_PATH
                                                        ))
                                                        -> validator(function($file) {
                                                            return $file["size"] >= 500000 ?
                                                                "Files must be smaller than 500KB" :
                                                                null;
                                                        })
                                                        -> allowedExtensions(array("png", "jpg", "bmp", "gif"), "Please upload an image")
                                                    )
    )
    ->leftJoin("reviews_images", "reviews.id_reviews", "=", "reviews_images.reviews_id")
    ->leftJoin("images", "images.id_images", "=", "reviews_images.images_id")
    ->process($_POST)
    ->json();

Any ideas on what could be causing the issue from this? If need be my SQL syntax is the following (and works 100%):

// Loading data
SELECT
    reviews.id_reviews,
    reviews.name,
    images.url
FROM reviews
LEFT JOIN reviews_images
    ON reviews.id_reviews = reviews_images.reviews_id
LEFT JOIN images
    ON images.id_images = reviews_images.images_id

Viewing all articles
Browse latest Browse all 82803

Trending Articles