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 c9cd22b8
authored
Jul 03, 2014
by
Aleksander Barszczewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modified model aggregate method to support distinct option and added test to tes…
…t/dao-factory.test.js
1 parent
0b3e25af
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
1 deletions
lib/model.js
test/dao-factory.test.js
lib/model.js
View file @
c9cd22b
...
@@ -822,7 +822,11 @@ module.exports = (function() {
...
@@ -822,7 +822,11 @@ module.exports = (function() {
Model
.
prototype
.
aggregate
=
function
(
field
,
aggregateFunction
,
options
)
{
Model
.
prototype
.
aggregate
=
function
(
field
,
aggregateFunction
,
options
)
{
options
=
Utils
.
_
.
extend
({
attributes
:
[]
},
options
||
{});
options
=
Utils
.
_
.
extend
({
attributes
:
[]
},
options
||
{});
options
.
attributes
.
push
([
this
.
sequelize
.
fn
(
aggregateFunction
,
this
.
sequelize
.
col
(
field
)),
aggregateFunction
]);
var
aggregateColumn
=
this
.
sequelize
.
col
(
field
);
if
(
options
.
distinct
)
{
aggregateColumn
=
this
.
sequelize
.
fn
(
'DISTINCT'
,
aggregateColumn
);
}
options
.
attributes
.
push
([
this
.
sequelize
.
fn
(
aggregateFunction
,
aggregateColumn
),
aggregateFunction
]);
if
(
!
options
.
dataType
)
{
if
(
!
options
.
dataType
)
{
if
(
this
.
rawAttributes
[
field
])
{
if
(
this
.
rawAttributes
[
field
])
{
...
...
test/dao-factory.test.js
View file @
c9cd22b
...
@@ -1174,6 +1174,28 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
...
@@ -1174,6 +1174,28 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
})
})
})
})
})
it
(
'supports distinct option'
,
function
(
done
)
{
var
Post
=
this
.
sequelize
.
define
(
'Post'
,{})
var
PostComment
=
this
.
sequelize
.
define
(
'PostComment'
,{})
Post
.
hasMany
(
PostComment
)
Post
.
sync
({
force
:
true
}).
success
(
function
()
{
PostComment
.
sync
({
force
:
true
}).
success
(
function
()
{
Post
.
create
({}).
success
(
function
(
post
){
PostComment
.
bulkCreate
([{
PostId
:
post
.
id
},{
PostId
:
post
.
id
}]).
success
(
function
(){
Post
.
count
({
include
:
[{
model
:
PostComment
,
required
:
false
}]
}).
success
(
function
(
count1
){
Post
.
count
({
distinct
:
true
,
include
:
[{
model
:
PostComment
,
required
:
false
}]
}).
success
(
function
(
count2
){
expect
(
count1
).
to
.
equal
(
2
)
expect
(
count2
).
to
.
equal
(
1
)
done
()
})
})
})
})
})
})
})
})
})
describe
(
'min'
,
function
()
{
describe
(
'min'
,
function
()
{
...
...
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