I am using Sequelize.js with paranoid mode set to true.
My issue is that when I try to soft delete a row using the Model.destroy method, it does not check if this row is referenced before soft deleting it. Before I started using paranoid, sequelize would throw an error when trying to destroy a row that was referenced, and I would like to keep this behaviour now that I am using paranoid.
I found two similiar questions about this matter:
Check if object is referenced to prevent soft-deleting without modifying database
Sequelize - Prevent destroying row when used somewhere else in association
The 1st one did not have a solution, but it had a restriction I do not have: touching the DB.
The 2nd one has the following solution:
User.hasMany(Roles, { foreignKey: "whatever", onDelete: 'restrict', onUpdate: 'restrict'});
It is definitely a solution but would result in a lot of work because I need to have this behaviour for all my tables and many of them are referenced by N other tables.
Is there a way to make sequelize always check for references before soft deleting? I don't have any restrictions as for touching the DB or running performance expensive queries on the beforeBulkDelete hook.