khareta
06/22/2021, 2:59 PMDB
._FavoriteItems
, CONSTRAINT _FavoriteItems_ibfk_1
FOREIGN KEY (A
) REFERENCES Item
(id
) ON DELETE CASCADE ON UPDATE CASCADE)`
this is the mysql table:
'CREATE TABLE `_FavoriteItems` (
`A` char(25) CHARACTER SET utf8 NOT NULL,
`B` char(25) CHARACTER SET utf8 NOT NULL,
UNIQUE KEY `_FavoriteItems_AB_unique` (`A`,`B`),
KEY `_FavoriteItems_B_index` (`B`),
CONSTRAINT `_FavoriteItems_ibfk_1` FOREIGN KEY (`A`) REFERENCES `Item` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `_FavoriteItems_ibfk_2` FOREIGN KEY (`B`) REFERENCES `User` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci'
this is the prisma model:
model Item {
favoritedBy User[] @relation("FavoriteItems")
}
model User {
favoriteItems Item[] @relation("FavoriteItems")
}
and this is the insert/connect statement:
INSERT IGNORE INTO
`DB`.`_FavoriteAds` (
`DB`.`_FavoriteItems`.`A`,
`DB`.`_FavoriteItems`.`B`
) VALUES ("itemId","userId")
Note that both itemId and userId exist in the database. A user can have many favorite items.janpio
khareta
06/22/2021, 7:49 PMkhareta
06/22/2021, 7:49 PMkhareta
06/22/2021, 7:51 PM