Skip to content

Joined primary key does not work as intended #8

Description

@NiklasAurora

With the following tables, I can not use the $tableIdColumn (#6). I am not allowed to save and instead it goes directly to update, as it can not find a joined primary key. However, as there is no row to update, nothing happens. If I remove the $tableIdColumn, I can save but I would not be able to update the OrderItem.

CREATE TABLE IF NOT EXISTS Product (
    `productID` INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL,
    `productManufacturer` VARCHAR(80) NOT NULL,
    `productName` VARCHAR(80) NOT NULL,
    `productOriginCountry` VARCHAR(40) NOT NULL,
    `productWeight` INTEGER NOT NULL,
    `productSize` VARCHAR(3) NOT NULL,
    `productSellPrize` INTEGER NOT NULL,
    `productBuyPrize` INTEGER NOT NULL,
    `productColor` VARCHAR(20) NOT NULL,
    `productAmount` INTEGER,
    `productCategoryID` INTEGER,
     FOREIGN KEY (`productCategoryID`) REFERENCES Category(`categoryID`)
) ENGINE INNODB CHARACTER SET utf8 COLLATE utf8_swedish_ci;
CREATE TABLE IF NOT EXISTS Orders (
    `orderID` INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL,
    `userID` INTEGER NOT NULL,
    `purchaseTime` DATETIME DEFAULT CURRENT_TIMESTAMP,
    `sentTime` DATETIME NULL,
    `couponID` INTEGER,
    `orderStatus` VARCHAR(40),
     FOREIGN KEY (`userID`) REFERENCES User(`userID`),
     FOREIGN KEY (`couponID`) REFERENCES Coupon(`couponID`)
) ENGINE INNODB CHARACTER SET utf8 COLLATE utf8_swedish_ci;
CREATE TABLE IF NOT EXISTS OrderItem (
    `orderID` INTEGER NOT NULL,
    `productID` INTEGER NOT NULL,
    `productAmount` INTEGER NOT NULL,
     PRIMARY KEY (`orderID`, `productID`),
     FOREIGN KEY (`orderID`) REFERENCES Orders(`orderID`),
     FOREIGN KEY (`productID`) REFERENCES Product(`productID`)
) ENGINE INNODB CHARACTER SET utf8 COLLATE utf8_swedish_ci;

PHP 7.1.7
MySQL Ver 14.14 Distrib 5.7.21
anax/database v1.1.9

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions