Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Joined primary key does not work as intended #8

Open
NiklasAurora opened this issue Mar 15, 2018 · 1 comment
Open

Joined primary key does not work as intended #8

NiklasAurora opened this issue Mar 15, 2018 · 1 comment

Comments

@NiklasAurora
Copy link
Contributor

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

@mosbth
Copy link
Member

mosbth commented Mar 16, 2018

I checked it up and it should be a possibility to use a primary key that is combined from several fields. But, I need to investigate.

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

No branches or pull requests

2 participants