Sequelize find soft deleted rows

﹥>﹥吖頭↗ 提交于 2020-01-24 03:16:07

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/32659318/sequelize-find-soft-deleted-rows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!