Closed codihuston closed 4 years ago
If fetching or updating a record, must use paranoid: true
option, and model.unscoped()
static method.
// create the user task
const [
userTask,
userTaskWasCreated
] = await this.models.userTask.unscoped().findOrCreate({
where: {
userId,
taskId: task.id
},
defaults: {
userId,
taskId: task.id,
description: input.description,
isPublic: input.isPublic,
eventColorId: input.eventColorId
},
// required w/ .unscoped() in order to find soft-deleted records
paranoid: false
});
If deleting a record, must use force: true
option with the .unscoped()
static method. It seems paranoid is not required here.
// delete it
// NOTE: using static method (public method is broken for postgres, which
// returns empty array [] as of 2020/01/27)
// SEE: https://github.com/sequelize/sequelize/issues/10508
const res = await this.models.userTask.unscoped().destroy({
where: {
userId,
id: input.userTaskId
},
// required to override soft delete
force: true
});
See a00f5d9eb0146b6e7401b
With a userTask being soft deleted, the .unscoped() method is not working; it appears to work for users (account deletion)...
See: https://sequelize.org/master/manual/scopes.html