mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
Adjusted
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Replace all junction rows for a course in one shot (delete + bulk create).
|
||||
*/
|
||||
async function syncJunction(Model, courseId, ids, fkField, transaction) {
|
||||
await Model.destroy({ where: { course_id: courseId }, transaction });
|
||||
if (ids?.length) {
|
||||
await Model.bulkCreate(
|
||||
ids.map((id) => ({ course_id: courseId, [fkField]: id })),
|
||||
{ transaction }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { syncJunction };
|
||||
Reference in New Issue
Block a user