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 65efbd3f
authored
Nov 18, 2016
by
Harshith Kashyap
Committed by
Jan Aagaard Meier
Nov 18, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
generateThroughJoin Fix - V3 port (#6878)
1 parent
20907581
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
110 additions
and
1 deletions
changelog.md
lib/dialects/abstract/query-generator.js
test/integration/include/findAll.test.js
changelog.md
View file @
65efbd3
# Future
-
[
ADDED
]
UPSERT support for MSSQL
-
[
FIXED
]
Incorrect column name for generateThroughJoin
# 3.25.0
-
[
FIXED
]
Set
`timestamps`
and
`paranoid`
options from through model on
`belongsToMany`
association
...
...
lib/dialects/abstract/query-generator.js
View file @
65efbd3
...
...
@@ -1307,7 +1307,7 @@ var QueryGenerator = {
var
isBelongsTo
=
topInclude
.
association
.
associationType
===
'BelongsTo'
;
var
join
=
[
self
.
quoteTable
(
topParent
.
model
.
name
)
+
'.'
+
self
.
quoteIdentifier
(
isBelongsTo
?
topInclude
.
association
.
identifierField
:
topParent
.
model
.
primaryKeyAttributes
[
0
]),
self
.
quoteIdentifier
(
topInclude
.
model
.
name
)
+
'.'
+
self
.
quoteIdentifier
(
isBelongsTo
?
top
Parent
.
model
.
primaryKeyAttributes
[
0
]
:
topInclude
.
association
.
identifierField
)
self
.
quoteIdentifier
(
topInclude
.
model
.
name
)
+
'.'
+
self
.
quoteIdentifier
(
isBelongsTo
?
top
Include
.
model
.
primaryKeyAttributes
[
0
]
:
topInclude
.
association
.
identifierField
)
].
join
(
' = '
);
$query
=
self
.
selectQuery
(
topInclude
.
model
.
tableName
,
{
attributes
:
[
topInclude
.
model
.
primaryKeyAttributes
[
0
]],
...
...
test/integration/include/findAll.test.js
View file @
65efbd3
...
...
@@ -1961,5 +1961,113 @@ describe(Support.getTestDialectTeaser('Include'), function() {
expect
(
parseInt
(
post
[
"comments.commentCount"
],
10
)).
to
.
equal
(
3
);
});
});
it
(
'Should return posts with nested include with inner join with a m:n association'
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
{
type
:
DataTypes
.
STRING
,
primaryKey
:
true
}
});
var
Entity
=
this
.
sequelize
.
define
(
'Entity'
,
{
entity_id
:
{
type
:
DataTypes
.
INTEGER
,
autoIncrement
:
true
,
primaryKey
:
true
},
creator
:
{
type
:
DataTypes
.
STRING
,
allowNull
:
false
},
votes
:
{
type
:
DataTypes
.
INTEGER
,
allowNull
:
false
,
defaultValue
:
0
}
});
var
Post
=
this
.
sequelize
.
define
(
'Post'
,
{
post_id
:
{
type
:
DataTypes
.
INTEGER
,
allowNull
:
false
,
primaryKey
:
true
}
});
var
TaggableSentient
=
this
.
sequelize
.
define
(
'TaggableSentient'
,
{
nametag
:
{
type
:
DataTypes
.
STRING
,
primaryKey
:
true
}
});
Entity
.
belongsTo
(
User
,
{
foreignKey
:
'creator'
,
targetKey
:
'username'
});
Post
.
belongsTo
(
Entity
,
{
foreignKey
:
'post_id'
,
targetKey
:
'entity_id'
});
Entity
.
belongsToMany
(
TaggableSentient
,
{
as
:
'tags'
,
through
:
{
model
:
'EntityTag'
,
unique
:
false
},
foreignKey
:
'entity_id'
,
otherKey
:
'tag_name'
});
TaggableSentient
.
belongsToMany
(
Entity
,
{
as
:
'tags'
,
through
:
{
model
:
'EntityTag'
,
unique
:
false
},
foreignKey
:
'tag_name'
,
otherKey
:
'entity_id'
});
return
this
.
sequelize
.
sync
({
force
:
true
})
.
then
(
function
()
{
return
User
.
create
({
username
:
'bob'
});
})
.
then
(
function
()
{
return
TaggableSentient
.
create
({
nametag
:
'bob'
});
})
.
then
(
function
()
{
return
Entity
.
create
({
creator
:
'bob'
});
})
.
then
(
function
(
entity
)
{
return
Promise
.
all
([
Post
.
create
({
post_id
:
entity
.
entity_id
}),
entity
.
addTags
(
'bob'
)
]);
})
.
then
(
function
()
{
var
options
=
{
include
:
[{
model
:
Entity
,
required
:
true
,
include
:
[{
model
:
User
,
required
:
true
},
{
model
:
TaggableSentient
,
as
:
'tags'
,
required
:
true
,
through
:
{
where
:
{
tag_name
:
[
'bob'
]
}
}
}]
}],
limit
:
5
,
offset
:
0
};
return
Post
.
findAll
(
options
);
})
.
then
(
function
(
posts
)
{
expect
(
posts
.
length
).
to
.
equal
(
1
);
expect
(
posts
[
0
].
Entity
.
creator
).
to
.
equal
(
'bob'
);
expect
(
posts
[
0
].
Entity
.
tags
.
length
).
to
.
equal
(
1
);
expect
(
posts
[
0
].
Entity
.
tags
[
0
].
EntityTag
.
tag_name
).
to
.
equal
(
'bob'
);
expect
(
posts
[
0
].
Entity
.
tags
[
0
].
EntityTag
.
entity_id
).
to
.
equal
(
posts
[
0
].
post_id
);
});
});
});
});
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