FeathersJS Sequelize Soft Delete

It might have been the late hour but spent over 1.5h chasing this the other day... and getting tangled up in config and softdelete2 feathers-plus hooks.

Turns out to setup soft deletes in FeathersJS using feathers-sequelize you only need the Sequelize built in paranoid option.

Here's the example that makes it clear.

sequelizeClient.define('exampleTable', {
	id: {
		type: DataTypes.BIGINT(20).UNSIGNED,
		primaryKey: true,
		autoIncrement: true,
	},
	...
}, {
	tableName: 'example_table',
	paranoid: true,
	deletedAt: 'deleted_at'
});

In essence:

  • no need to define a field for deleted_at
  • add the paranoid: true option to your sequelize model
  • add the field name deletedAt: 'deleted_at' option to your sequelize model (if using alt name)
  • sequelize model option timestamps: true should be set, though it is the default, so you likely won't need to declare it

If you need a query that includes the soft deleted items set paranoid: false in a hook.

context => {
	context.params.sequelize = {paranoid: false};
}

Any includes will need their paranoid flag set:

context => {
	context.params.sequelize = {
		include: [{
			model: SomeModel,
			paranoid: false
		}], 
		paranoid: false
	};
}