Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(syntax): correct parentheses around union (#9813)
- Loading branch information
1 parent
fcd07ef
commit aadbe0d
Showing
3 changed files
with
109 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
'use strict'; | ||
|
||
const chai = require('chai'); | ||
const expect = chai.expect; | ||
const Support = require('../../support'); | ||
const DataTypes = require('../../../../lib/data-types'); | ||
const Sequelize = require('../../../../lib/sequelize'); | ||
const current = Support.sequelize; | ||
|
||
describe(Support.getTestDialectTeaser('Model'), () => { | ||
describe('findAll', () => { | ||
describe('separate with limit', () => { | ||
it('should not throw syntax error (union)', () => { | ||
// #9813 testcase | ||
const Project = current.define('Project', { name: DataTypes.STRING }); | ||
const LevelTwo = current.define('LevelTwo', { name: DataTypes.STRING }); | ||
const LevelThree = current.define('LevelThree', { type: DataTypes.INTEGER }); | ||
|
||
Project.hasMany(LevelTwo); | ||
LevelTwo.belongsTo(Project); | ||
|
||
LevelTwo.hasMany(LevelThree, { as: 'type_ones' }); | ||
LevelTwo.hasMany(LevelThree, { as: 'type_twos' }); | ||
LevelThree.belongsTo(LevelTwo); | ||
|
||
return current.sync({ force: true }).then(() => { | ||
return Sequelize.Promise.all([ | ||
Project.create({ name: 'testProject' }), | ||
LevelTwo.create({ name: 'testL21' }), | ||
LevelTwo.create({ name: 'testL22' }) | ||
]); | ||
}).spread((project, level21, level22) => { | ||
return Sequelize.Promise.all([ | ||
project.addLevelTwo(level21), | ||
project.addLevelTwo(level22) | ||
]); | ||
}).spread(() => { | ||
// one include case | ||
return Project.findAll({ | ||
where: { name: 'testProject' }, | ||
include: [ | ||
{ | ||
model: LevelTwo, | ||
include: [ | ||
{ | ||
model: LevelThree, | ||
as: 'type_ones', | ||
where: { type: 0 }, | ||
separate: true, | ||
limit: 1, | ||
order: [['createdAt', 'DESC']] | ||
} | ||
] | ||
} | ||
] | ||
}); | ||
}).then(() => { | ||
}, () => { | ||
expect.fail(); | ||
}).then(() => { | ||
// two includes case | ||
return Project.findAll({ | ||
where: { name: 'testProject' }, | ||
include: [ | ||
{ | ||
model: LevelTwo, | ||
include: [ | ||
{ | ||
model: LevelThree, | ||
as: 'type_ones', | ||
where: { type: 0 }, | ||
separate: true, | ||
limit: 1, | ||
order: [['createdAt', 'DESC']] | ||
}, | ||
{ | ||
model: LevelThree, | ||
as: 'type_twos', | ||
where: { type: 1 }, | ||
separate: true, | ||
limit: 1, | ||
order: [['createdAt', 'DESC']] | ||
} | ||
] | ||
} | ||
] | ||
}); | ||
}).then(() => { | ||
}, () => { | ||
expect.fail(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters