Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sequelize find soft deleted rows

I'm trying to get some rows from database that are soft deleted AND some that are not, but it's not working for me.

Model.findAll({
    'where': {
        cond: 'xxx'
    },
    include: [Model2],
    paranoid: false
}).then(function (rows) {
    // do something
}).catch(function (err) {
    // do something
});

How can I do it?

like image 249
kecal909 Avatar asked Sep 18 '15 19:09

kecal909


1 Answers

The query you have should include instances of Model that have been soft-deleted, but won't include instances of Model2 that are soft-deleted.

To get the soft-deleted Model2 instances, you'll also need the paranoid: false option within the include:

Model.findAll({
    'where': {
        cond: 'xxx'
    },
    include: [{
        model: Model2,
        paranoid: false
    }], 
    paranoid: false
}).then(function (rows) {
    // do something
}).catch(function (err) {
    // do something
});

This doesn't seem to be in the documentation, but I tried it and it worked.

like image 123
treythomas123 Avatar answered Oct 03 '22 02:10

treythomas123