feat: add omitIds

This commit is contained in:
Marc-Roig 2023-03-28 14:37:02 +02:00 committed by Josh
parent 2ac90b8e8e
commit 49f290ff97

View File

@ -2,7 +2,13 @@
const { cleanInverseOrderColumn } = require('../../regular-relations');
const replaceRegularRelations = async ({ targetId, sourceId, attribute, transaction: trx }) => {
const replaceRegularRelations = async ({
targetId,
sourceId,
attribute,
omitIds,
transaction: trx,
}) => {
const { joinTable } = attribute;
const { joinColumn, inverseJoinColumn } = joinTable;
@ -11,8 +17,7 @@ const replaceRegularRelations = async ({ targetId, sourceId, attribute, transact
.createQueryBuilder(joinTable.name)
.update({ [joinColumn.name]: targetId })
.where({ [joinColumn.name]: sourceId })
// TODO: Exclude some relations from being replaced
// .where({ $not: { [inverseJoinColumn.name]: relationsToDeleteIds } })
.where({ $not: { [inverseJoinColumn.name]: omitIds } })
.onConflict([joinColumn.name, inverseJoinColumn.name])
.ignore()
.transacting(trx)
@ -39,7 +44,7 @@ const cloneRegularRelations = async ({ targetId, sourceId, attribute, transactio
)
.where(joinColumn.name, sourceId)
// TODO: Exclude some relations from being replaced
// .where({ $not: { [inverseJoinColumn.name]: relationsToDeleteIds } })
// .where({ $not: { [inverseJoinColumn.name]: omitIds } })
.from(joinTable.name)
.toSQL();