不要怂,就是干,撸起袖子干!

Commit ed2d7a90 by Juarez Lustosa Committed by GitHub

fix(model.destroy): return 0 with truncate (#12281)

1 parent 72925cf7
...@@ -199,7 +199,7 @@ class Query extends AbstractQuery { ...@@ -199,7 +199,7 @@ class Query extends AbstractQuery {
return rowCount; return rowCount;
} }
if (this.isBulkDeleteQuery()) { if (this.isBulkDeleteQuery()) {
return data[0] && data[0].AFFECTEDROWS; return data[0] ? data[0].AFFECTEDROWS : 0;
} }
if (this.isVersionQuery()) { if (this.isVersionQuery()) {
return data[0].version; return data[0].version;
......
...@@ -97,7 +97,7 @@ class Query extends AbstractQuery { ...@@ -97,7 +97,7 @@ class Query extends AbstractQuery {
(count, r) => Number.isFinite(r.rowCount) ? count + r.rowCount : count, (count, r) => Number.isFinite(r.rowCount) ? count + r.rowCount : count,
0 0
) )
: queryResult.rowCount; : queryResult.rowCount || 0;
if (this.sequelize.options.minifyAliases && this.options.aliasesMapping) { if (this.sequelize.options.minifyAliases && this.options.aliasesMapping) {
rows = rows rows = rows
...@@ -396,7 +396,6 @@ class Query extends AbstractQuery { ...@@ -396,7 +396,6 @@ class Query extends AbstractQuery {
} }
} }
module.exports = Query; module.exports = Query;
module.exports.Query = Query; module.exports.Query = Query;
module.exports.default = Query; module.exports.default = Query;
...@@ -1238,6 +1238,15 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -1238,6 +1238,15 @@ describe(Support.getTestDialectTeaser('Model'), () => {
expect(await User.findAll()).to.have.lengthOf(0); expect(await User.findAll()).to.have.lengthOf(0);
}); });
it('`truncate` option returns a number', async function() {
const User = this.sequelize.define('User', { username: DataTypes.STRING });
await this.sequelize.sync({ force: true });
await User.bulkCreate([{ username: 'user1' }, { username: 'user2' }]);
const affectedRows = await User.destroy({ truncate: true });
expect(await User.findAll()).to.have.lengthOf(0);
expect(affectedRows).to.be.a('number');
});
it('throws an error if no where clause is given', async function() { it('throws an error if no where clause is given', async function() {
const User = this.sequelize.define('User', { username: DataTypes.STRING }); const User = this.sequelize.define('User', { username: DataTypes.STRING });
await this.sequelize.sync({ force: true }); await this.sequelize.sync({ force: true });
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!