不要怂,就是干,撸起袖子干!

Commit 3b623cbf by Jozef Hartinger Committed by Sushant

fix(query-generator): 1-to-many join in subQuery filter missing where clause (#9228) (#9247)

1 parent 2da9e4df
......@@ -1663,9 +1663,10 @@ const QueryGenerator = {
include: Model._validateIncludedElements(topInclude).include,
model: topInclude.model,
where: {
[Op.and]: [{
[Op.join]: this.sequelize.asIs(join)
}]
[Op.and]: [
topInclude.where,
{ [Op.join]: this.sequelize.asIs(join) }
]
},
limit: 1,
tableAs: topInclude.as,
......
......@@ -31,6 +31,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
* |
* |
* |
* N
* [Footnote]
*/
beforeEach(function () {
......@@ -360,7 +361,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
});
/*
* one-to-one
* one-to-many
*/
it('supports required one-to-many association', function () {
return this.sequelize.sync({ force: true })
......@@ -391,20 +392,23 @@ describe(Support.getTestDialectTeaser('Include'), () => {
return this.sequelize.sync({ force: true })
.then(() => Promise.join(
this.Post.bulkCreate(build('alpha', 'bravo', 'charlie')),
this.Comment.bulkCreate(build('comment0', 'comment1'))
this.Comment.bulkCreate(build('comment0', 'comment1', 'comment2'))
))
.spread((posts, comments) => Promise.join(
posts[0].addComment(comments[0]),
posts[2].addComment(comments[1])
posts[1].addComment(comments[1]),
posts[2].addComment(comments[2])
))
.then(() => this.Post.findAll({
include: [{
model: this.Comment,
required: true,
where: {
name: {
[this.sequelize.Op.like]: 'comment%'
}
[Op.or]: [{
name: 'comment0'
}, {
name: 'comment2'
}]
}
}],
order: ['name'],
......@@ -417,6 +421,31 @@ describe(Support.getTestDialectTeaser('Include'), () => {
});
});
it('supports required one-to-many association with where clause (findOne)', function () {
return this.sequelize.sync({ force: true })
.then(() => Promise.join(
this.Post.bulkCreate(build('alpha', 'bravo', 'charlie')),
this.Comment.bulkCreate(build('comment0', 'comment1', 'comment2'))
))
.spread((posts, comments) => Promise.join(
posts[0].addComment(comments[0]),
posts[1].addComment(comments[1]),
posts[2].addComment(comments[2])
))
.then(() => this.Post.findOne({
include: [{
model: this.Comment,
required: true,
where: {
name: 'comment2'
}
}]
}))
.then(post => {
expect(post.name).to.equal('charlie');
});
});
it('supports 2 levels of required one-to-many associations', function () {
return this.sequelize.sync({ force: true })
.then(() => Promise.join(
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!