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 f5fcf164
authored
Dec 04, 2017
by
Ilyes Hermellin
Committed by
Sushant
Dec 04, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(associations/has-many): use scoped primary field on count to prevent ambiguo…
…us column error (#8732)
1 parent
a23d9604
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
1 deletions
lib/associations/has-many.js
test/integration/associations/has-many.test.js
lib/associations/has-many.js
View file @
f5fcf16
...
@@ -250,7 +250,7 @@ class HasMany extends Association {
...
@@ -250,7 +250,7 @@ class HasMany extends Association {
options
=
Utils
.
cloneDeep
(
options
);
options
=
Utils
.
cloneDeep
(
options
);
options
.
attributes
=
[
options
.
attributes
=
[
[
sequelize
.
fn
(
'COUNT'
,
sequelize
.
col
(
model
.
primaryKeyField
)),
'count'
]
[
sequelize
.
fn
(
'COUNT'
,
sequelize
.
col
(
model
.
name
.
concat
(
'.'
,
model
.
primaryKeyField
)
)),
'count'
]
];
];
options
.
raw
=
true
;
options
.
raw
=
true
;
options
.
plain
=
true
;
options
.
plain
=
true
;
...
...
test/integration/associations/has-many.test.js
View file @
f5fcf16
...
@@ -26,6 +26,44 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
...
@@ -26,6 +26,44 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
});
});
});
});
describe
(
'count'
,
()
=>
{
it
(
'should not fail due to ambiguous field'
,
function
()
{
const
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
DataTypes
.
STRING
}),
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
DataTypes
.
STRING
,
active
:
DataTypes
.
BOOLEAN
});
User
.
hasMany
(
Task
);
const
subtasks
=
Task
.
hasMany
(
Task
,
{
as
:
'subtasks'
});
return
this
.
sequelize
.
sync
({
force
:
true
}).
then
(()
=>
{
return
User
.
create
({
username
:
'John'
,
Tasks
:
[{
title
:
'Get rich'
,
active
:
true
}]
},
{
include
:
[
Task
]
});
}).
then
(
user
=>
{
return
Promise
.
join
(
user
.
get
(
'Tasks'
)[
0
].
createSubtask
({
title
:
'Make a startup'
,
active
:
false
}),
user
.
get
(
'Tasks'
)[
0
].
createSubtask
({
title
:
'Engage rock stars'
,
active
:
true
})
).
return
(
user
);
}).
then
(
user
=>
{
return
expect
(
user
.
countTasks
({
attributes
:
[
Task
.
primaryKeyField
,
'title'
],
include
:
[{
attributes
:
[],
association
:
subtasks
,
where
:
{
active
:
true
}
}],
group
:
this
.
sequelize
.
col
(
Task
.
name
.
concat
(
'.'
,
Task
.
primaryKeyField
))
})).
to
.
eventually
.
equal
(
1
);
});
});
});
describe
(
'get'
,
()
=>
{
describe
(
'get'
,
()
=>
{
if
(
current
.
dialect
.
supports
.
groupedLimit
)
{
if
(
current
.
dialect
.
supports
.
groupedLimit
)
{
describe
(
'multiple'
,
()
=>
{
describe
(
'multiple'
,
()
=>
{
...
...
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