module.exports = Self => { Self.observe('before save', async ctx => { const models = Self.app.models; const changes = ctx.data || ctx.instance; const instance = ctx.currentInstance; const workerFk = changes?.workerFk || instance?.workerFk; if (workerFk) { const locker = await models.Locker.findOne({ where: {workerFk} }, ctx.options); if (locker) { await Self.rawSql( 'UPDATE locker SET workerFk = NULL where workerFk = ?', [workerFk], ctx.options); } } }); };