
Product
Introducing Rust Support in Socket
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.
bookshelf-cascade-soft-delete
Advanced tools
This is a plugin to be used with [Bookshelf JS](http://bookshelfjs.org/). It's the combination of two existing plugins, [node-bookshelf-soft-delete](https://github.com/lanetix/node-bookshelf-soft-delete) and [bookshelf-cascade-delete](https://github.com/s
This is a plugin to be used with Bookshelf JS. It's the combination of two existing plugins, node-bookshelf-soft-delete and bookshelf-cascade-delete, as well as custom code to accomplish the cacade soft deletions.
Intall the package via npm:
$ npm install --save bookshelf-cascade-soft-delete
In reality, nothing changes from the documentation of node-bookshelf-soft-delete and bookshelf-cascade-delete. You just need the combined functionality. Their documentation is great and easy to follow.
const bookshelf = require('../config/bookshelf');
const CompanyAddress = require('./CompanyAddress');
const Crew = require('./Crew');
bookshelf.plugin('registry');
bookshelf.plugin(require('bookshelf-cascade-soft-delete'));
module.exports = bookshelf.model('Company', {
tableName: 'companies',
defaults: {
name: 'company',
},
company_address: function() {
return this.hasOne(CompanyAddress);
},
crews: function() {
return this.hasMany(Crew);
},
soft: true
}, {
dependents: ['company_address', 'crews'],
});
Declaring soft: true will make any instances of the model will add 'deleted_at' and 'restored_at' fields to the table, by default. The names of those fields can be customized by the following:
soft: ['deletionDate', 'restorationDate']
The dependents field declares which child models will be cascade deleted. If you want them to be soft deleted, you need to declare the soft field on those models as well.
In your delete endpoint, you simply call destroy on the record. The destroy method can execute soft, cascade, and normal deletes, depending on your model setup.
const Company = require('./models/Company');
app.delete('/company', async (req, res, next) => {
try {
await new Company({ id: req.body.company_id }).destroy();
res.status(200).send({ deleteCompany: 'success' });
} catch (err) {
next(err);
}
});
FAQs
This is a plugin to be used with [Bookshelf JS](http://bookshelfjs.org/). It's the combination of two existing plugins, [node-bookshelf-soft-delete](https://github.com/lanetix/node-bookshelf-soft-delete) and [bookshelf-cascade-delete](https://github.com/s
We found that bookshelf-cascade-soft-delete demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.
Product
Socket’s precomputed reachability slashes false positives by flagging up to 80% of vulnerabilities as irrelevant, with no setup and instant results.
Product
Socket is launching experimental protection for Chrome extensions, scanning for malware and risky permissions to prevent silent supply chain attacks.