I am a beginner in JavaScript and I am currently working on creating a new restaurant. I have come across a code snippet that inserts a relation into a join-table:
await newRestaurant.$relatedQuery('tags', trx).relate(tagIds);
Is it not possible to do this with MySQL? What is the alternative solution for this issue? When testing with Postman, I received the following message:
"message": "batch insert only works with Postgresql and SQL Server"
The tags are associated with a model class called RestaurantTag, which contains fields like id and name. The relationship is many-to-many mapped with the Restaurant model.
export const createRestaurant: ExpressHandlerFn = async (req, res, next) => {
try {
const {
name,
description,
address,
cityId,
priceTier,
phoneNumber,
schedule,
tagIds,
} = req.body;
const { thumbnailImage, galleryImages } = req.files as MulterFields;
const userId = req.session!.id;
const createRestaurantTransaction = await Restaurant.transaction(async (trx) => {
let newRestaurant = await Restaurant.query(trx).insertGraphAndFetch({
name,
description,
priceTier,
address,
cityId,
phoneNumber,
schedule,
});
await newRestaurant.$relatedQuery('tags', trx).relate(tagIds);
If there is any information missing or if you can provide assistance on this matter, please feel free to share your insights! Your help is greatly appreciated.