返回错误的已删除记录数

时间:2018-05-08 08:20:49

标签: node.js sequelize.js

我有一个定期发生的问题。它不依赖于要删除的行数。我无法找到一个模型。换句话说,它可能发生在2行,甚至是100!

问题: 我发送了一个ID数组,用于我希望删除的行。删除总是成功的(无法找到后面的行)。 Sequalize(3.24.6)有时会将其删除0行,而我知道它已被正确删除。

CODE: 在我的存储库中:

deleteAccountProfileEntries(idArray) {
        return this.storage.deleteProfileEntries(idArray).then((erasedCount) => {
            if (idArray.length !== erasedCount) {
                throw new Error('invalid amount of records removed');
            }
        });    
    }

然后打电话给存储:

deleteProfileEntries(profileEntryIds) {
        if (!Array.isArray(profileEntryIds)) {
            throw new Error('Expected an array as an input');
        }
        return model.profile_entries.destroy({
            where: {
                id: {
                    $in: profileEntryIds
                }
            }
        });
    }

问题起源于这一行:

if (idArray.length !== erasedCount) {
                throw new Error('invalid amount of records removed');
            }

所以,即使它删除了它们,有时它返回的删除也是零。 我可以轻松删除此检查,但我想知道原因。

0 个答案:

没有答案