diff --git a/lib/model.js b/lib/model.js index 3ac585242bf5..9a7dfcd386e0 100644 --- a/lib/model.js +++ b/lib/model.js @@ -1984,9 +1984,6 @@ class Model { options = this._paranoidClause(this, options); const value = await this.queryInterface.rawSelect(this.getTableName(options), options, aggregateFunction, this); - if (value === null) { - return 0; - } return value; } diff --git a/test/integration/model/notExist.test.js b/test/integration/model/notExist.test.js index b8b0dd017f01..e85c736e4ad2 100644 --- a/test/integration/model/notExist.test.js +++ b/test/integration/model/notExist.test.js @@ -22,12 +22,13 @@ describe(Support.getTestDialectTeaser('Model'), () => { { sequence: 3, amount: 5, type: 'A' }, { sequence: 4, amount: 1, type: 'A' }, { sequence: 1, amount: 2, type: 'B' }, - { sequence: 2, amount: 6, type: 'B' } + { sequence: 2, amount: 6, type: 'B' }, + { sequence: 0, amount: 0, type: 'C' } ]); }); describe('max', () => { - it('should type exist', async function() { + it('type A to C should exist', async function() { await expect(this.Order.sum('sequence', { where: { type: 'A' } })).to.eventually.be.equal(10); await expect(this.Order.max('sequence', { where: { type: 'A' } })).to.eventually.be.equal(4); await expect(this.Order.min('sequence', { where: { type: 'A' } })).to.eventually.be.equal(1); @@ -41,18 +42,22 @@ describe(Support.getTestDialectTeaser('Model'), () => { await expect(this.Order.sum('amount', { where: { type: 'B' } })).to.eventually.be.equal(8); await expect(this.Order.max('amount', { where: { type: 'B' } })).to.eventually.be.equal(6); await expect(this.Order.min('amount', { where: { type: 'B' } })).to.eventually.be.equal(2); - }); - it('should type not exist', async function() { - // DataTypes.INTEGER or DataTypes.BIGINT: previous version should use `.to.eventually.be.NaN` await expect(this.Order.sum('sequence', { where: { type: 'C' } })).to.eventually.be.equal(0); await expect(this.Order.max('sequence', { where: { type: 'C' } })).to.eventually.be.equal(0); await expect(this.Order.min('sequence', { where: { type: 'C' } })).to.eventually.be.equal(0); - - // DataTypes.DECIMAL or DataTypes.FLOAT: previous and PR#13422 both use `to.eventually.be.equal(0)` await expect(this.Order.sum('amount', { where: { type: 'C' } })).to.eventually.be.equal(0); await expect(this.Order.max('amount', { where: { type: 'C' } })).to.eventually.be.equal(0); await expect(this.Order.min('amount', { where: { type: 'C' } })).to.eventually.be.equal(0); }); + + it('type D should not exist', async function() { + await expect(this.Order.sum('sequence', { where: { type: 'D' } })).to.eventually.be.null; + await expect(this.Order.max('sequence', { where: { type: 'D' } })).to.eventually.be.null; + await expect(this.Order.min('sequence', { where: { type: 'D' } })).to.eventually.be.null; + await expect(this.Order.sum('amount', { where: { type: 'D' } })).to.eventually.be.null; + await expect(this.Order.max('amount', { where: { type: 'D' } })).to.eventually.be.null; + await expect(this.Order.min('amount', { where: { type: 'D' } })).to.eventually.be.null; + }); }); }); diff --git a/test/integration/model/sum.test.js b/test/integration/model/sum.test.js index 4f0aad682f24..081592e3a94f 100644 --- a/test/integration/model/sum.test.js +++ b/test/integration/model/sum.test.js @@ -28,7 +28,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { describe('sum', () => { it('should sum without rows', async function() { - await expect(this.Payment.sum('amount', { where: { mood: 'sad' } })).to.eventually.be.equal(0); + await expect(this.Payment.sum('amount', { where: { mood: 'sad' } })).to.eventually.be.null; }); it('should sum when is 0', async function() {