View soft-deleted records
Sequelize supports the concept of paranoid tables. A paranoid table is one that, when told to delete a record, it will not truly delete it. Instead, a special column called deletedAt
will have its value set to the timestamp of that deletion request.
This means that paranoid tables perform a soft-deletion of records, instead of a hard-deletion. By default, Forest Admin hides soft-deleted records. This example will show you how to view soft-deleted records within your Forest Admin interface.
Define hooks on your model
Sequelize hooks are places we can write callbacks that get invoked at key points in time like afterCreate
, afterDestroy
, afterUpdate
, and more.
Here, we'll use beforeFind
and beforeCount
hooks ont our Companies model.
module.exports = (sequelize, DataTypes) => {
const { Sequelize } = sequelize;
const Companies = sequelize.define('companies', {
name: {
type: DataTypes.STRING,
allowNull: false,
},
score: {
type: DataTypes.INTEGER,
},
address: {
type: DataTypes.STRING,
},
}, {
tableName: 'companies',
schema: process.env.DATABASE_SCHEMA,
paranoid: true,
hooks: {
beforeFind(options) {
options.paranoid = false; // Hooks used to display soft-deleted records
},
beforeCount(options) {
options.paranoid = false; // Hooks used to count soft-deleted records
},
},
});
Companies.associate = (models) => {
};
return Companies;
};
Use segments
For better visibility, you can create a segment to display your deleted records.


Last updated
Was this helpful?