lakenen lakenen - 1 year ago 341
Javascript Question

Sequelize.js delete query?

Is there a way to write a delete/deleteAll query like findAll?

For example I want to do something like this (assuming MyModel is a Sequelize model...):

MyModel.deleteAll({ where: ['some_field != ?', something] })
.on('success', function() { /* ... */ });

Answer Source

I've searched deep into the code, step by step into the following files:

What I found:

There isn't a deleteAll method, there's a destroy() method you can call on a record, for example:

Project.find(123).on('success', function(project) {
  project.destroy().on('success', function(u) {
    if (u && u.deletedAt) {
      // successfully deleted the project
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download