2017-05-02 73 views
2

這裏是我的數據庫中刪除行代碼Sequelize如何返回被毀

Model.destroy({ 
    where: { 
    ... 
    } 
}).then((response) => { 
    console.log(response) 
}) 

我所得到的console.log01記錄是否被刪除或不..

這是任何方式在承諾中返回被毀壞的行?

所以反應應該是這樣的{ID:123,...}

+0

增加了一些更新。 –

回答

4

UpdateDestroy不工作的方式。所以你不能,但有一個辦法。

Model.find({ 
    where: {...} 
}).then((result) => { 
    return Model.destroy({where: ..}) 
       .then((u) => {return result}); 
}); 

在這裏,我們正在返回一個承諾爲Model.destroy從呼叫收到Model.findresult對象,這將解決。

所以,讓我們說有一個叫delete定義功能:

function delete() { 
    Model.find({ 
     where: { ...} 
    }).then((result) => { 
     return Model.destroy({ where: ..}) 
      .then((u) => { return result }); 
    }); 
} 

您可以使用delete爲:

delete.then(findResult => console.log(JSON.stringify(findResult)); 
+0

謝謝蘇哈爾..還沒有實施,但我相信它會沒問題...那麼你確定沒有辦法檢索刪除記錄沒有2查詢? – Devsullo

+0

也許你可以使用備份文件。我不知道有任何可用的恢復工具。但這很好。 –