Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit 5db576a2
authored
Oct 11, 2018
by
Tiago Bonatti
Committed by
Sushant
Oct 11, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(model): sum returns zero when empty matching (#9984)
1 parent
ded97557
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
2 deletions
lib/model.js
lib/query-interface.js
test/integration/model/sum.test.js
lib/model.js
View file @
5db576a
...
...
@@ -1958,7 +1958,12 @@ class Model {
Utils
.
mapOptionFieldNames
(
options
,
this
);
options
=
this
.
_paranoidClause
(
this
,
options
);
return
this
.
QueryInterface
.
rawSelect
(
this
.
getTableName
(
options
),
options
,
aggregateFunction
,
this
);
return
this
.
QueryInterface
.
rawSelect
(
this
.
getTableName
(
options
),
options
,
aggregateFunction
,
this
).
then
(
value
=>
{
if
(
value
===
null
)
{
return
0
;
}
return
value
;
});;
}
/**
...
...
lib/query-interface.js
View file @
5db576a
...
...
@@ -1136,7 +1136,9 @@ class QueryInterface {
const
dataType
=
options
.
dataType
;
if
(
dataType
instanceof
DataTypes
.
DECIMAL
||
dataType
instanceof
DataTypes
.
FLOAT
)
{
result
=
parseFloat
(
result
);
if
(
!
_
.
isNull
(
result
))
{
result
=
parseFloat
(
result
);
}
}
else
if
(
dataType
instanceof
DataTypes
.
INTEGER
||
dataType
instanceof
DataTypes
.
BIGINT
)
{
result
=
parseInt
(
result
,
10
);
}
else
if
(
dataType
instanceof
DataTypes
.
DATE
)
{
...
...
test/integration/model/sum.test.js
0 → 100644
View file @
5db576a
'use strict'
;
const
chai
=
require
(
'chai'
),
expect
=
chai
.
expect
,
Support
=
require
(
'../support'
),
DataTypes
=
require
(
'../../../lib/data-types'
);
describe
(
Support
.
getTestDialectTeaser
(
'Model'
),
()
=>
{
beforeEach
(
function
()
{
this
.
Payment
=
this
.
sequelize
.
define
(
'Payment'
,
{
amount
:
DataTypes
.
DECIMAL
,
mood
:
{
type
:
DataTypes
.
ENUM
,
values
:
[
'happy'
,
'sad'
,
'neutral'
]
}
});
return
this
.
sequelize
.
sync
({
force
:
true
}).
then
(()
=>
{
return
this
.
Payment
.
bulkCreate
([
{
amount
:
5
,
mood
:
'neutral'
},
{
amount
:
-
5
,
mood
:
'neutral'
},
{
amount
:
10
,
mood
:
'happy'
},
{
amount
:
90
,
mood
:
'happy'
}
]);
});
});
describe
(
'sum'
,
()
=>
{
it
(
'should sum without rows'
,
function
()
{
return
expect
(
this
.
Payment
.
sum
(
'amount'
,
{
where
:
{
mood
:
'sad'
}})).
to
.
eventually
.
be
.
equal
(
0
);
});
it
(
'should sum when is 0'
,
function
()
{
return
expect
(
this
.
Payment
.
sum
(
'amount'
,
{
where
:
{
mood
:
'neutral'
}})).
to
.
eventually
.
be
.
equal
(
0
);
});
it
(
'should sum'
,
function
()
{
return
expect
(
this
.
Payment
.
sum
(
'amount'
,
{
where
:
{
mood
:
'happy'
}})).
to
.
eventually
.
be
.
equal
(
100
);
});
});
});
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment