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 1fe24016
authored
Oct 05, 2019
by
warkenji
Committed by
Sushant
Oct 05, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(sequelize.col): associations (#11419)
1 parent
3834fe20
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
1 deletions
lib/dialects/abstract/query-generator.js
test/integration/include.test.js
lib/dialects/abstract/query-generator.js
View file @
1fe2401
...
@@ -898,7 +898,7 @@ class QueryGenerator {
...
@@ -898,7 +898,7 @@ class QueryGenerator {
if
(
identifiers
.
includes
(
'.'
))
{
if
(
identifiers
.
includes
(
'.'
))
{
identifiers
=
identifiers
.
split
(
'.'
);
identifiers
=
identifiers
.
split
(
'.'
);
const
head
=
identifiers
.
slice
(
0
,
identifiers
.
length
-
1
).
join
(
'
.
'
);
const
head
=
identifiers
.
slice
(
0
,
identifiers
.
length
-
1
).
join
(
'
->
'
);
const
tail
=
identifiers
[
identifiers
.
length
-
1
];
const
tail
=
identifiers
[
identifiers
.
length
-
1
];
return
`
${
this
.
quoteIdentifier
(
head
)}
.
${
this
.
quoteIdentifier
(
tail
)}
`
;
return
`
${
this
.
quoteIdentifier
(
head
)}
.
${
this
.
quoteIdentifier
(
tail
)}
`
;
...
...
test/integration/include.test.js
View file @
1fe2401
...
@@ -48,6 +48,58 @@ describe(Support.getTestDialectTeaser('Include'), () => {
...
@@ -48,6 +48,58 @@ describe(Support.getTestDialectTeaser('Include'), () => {
});
});
});
});
it
(
'should support to use associations with Sequelize.col'
,
function
()
{
const
Table1
=
this
.
sequelize
.
define
(
'Table1'
);
const
Table2
=
this
.
sequelize
.
define
(
'Table2'
);
const
Table3
=
this
.
sequelize
.
define
(
'Table3'
,
{
value
:
DataTypes
.
INTEGER
});
Table1
.
hasOne
(
Table2
,
{
foreignKey
:
'Table1Id'
});
Table2
.
hasMany
(
Table3
,
{
as
:
'Tables3'
,
foreignKey
:
'Table2Id'
});
return
this
.
sequelize
.
sync
({
force
:
true
}).
then
(()
=>
{
return
Table1
.
create
().
then
(
table1
=>
{
return
Table2
.
create
({
Table1Id
:
table1
.
get
(
'id'
)
});
}).
then
(
table2
=>
{
return
Table3
.
bulkCreate
([
{
Table2Id
:
table2
.
get
(
'id'
),
value
:
5
},
{
Table2Id
:
table2
.
get
(
'id'
),
value
:
7
}
],
{
validate
:
true
});
});
}).
then
(()
=>
{
return
Table1
.
findAll
({
raw
:
true
,
attributes
:
[
[
Sequelize
.
fn
(
'SUM'
,
Sequelize
.
col
(
'Table2.Tables3.value'
)),
'sum'
]
],
include
:
[
{
model
:
Table2
,
attributes
:
[],
include
:
[
{
model
:
Table3
,
as
:
'Tables3'
,
attributes
:
[]
}
]
}
]
}).
then
(
result
=>
{
expect
(
result
.
length
).
to
.
equal
(
1
);
expect
(
parseInt
(
result
[
0
].
sum
,
10
)).
to
.
eq
(
12
);
});
});
});
it
(
'should support a belongsTo association reference with a where'
,
function
()
{
it
(
'should support a belongsTo association reference with a where'
,
function
()
{
const
Company
=
this
.
sequelize
.
define
(
'Company'
,
{
name
:
DataTypes
.
STRING
}),
const
Company
=
this
.
sequelize
.
define
(
'Company'
,
{
name
:
DataTypes
.
STRING
}),
User
=
this
.
sequelize
.
define
(
'User'
,
{}),
User
=
this
.
sequelize
.
define
(
'User'
,
{}),
...
...
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