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

Commit cf967349 by Mick Hansen

fix(include): fix issue with bad query generation on empty include.where, closes #3099

1 parent 007d20bd
# Next
- [BUG] Fixed issue with empty `include.where`
# 2.0.0
- [BUG] Fixed `field` support for `increment` and `decrement`.
- [FEATURE/BUG] Raw queries always return all results (including affected rows etc). This means you should change all promise listeners on `sequelize.query` to use `.spread` instead of `.then`, unless you are passing a query type.
......
......@@ -905,7 +905,8 @@ module.exports = (function() {
, through = include.through
, joinType = include.required ? ' INNER JOIN ' : ' LEFT OUTER JOIN '
, includeWhere = {}
, whereOptions = Utils._.clone(options);
, whereOptions = Utils._.clone(options)
, targetWhere;
whereOptions.keysEscaped = true;
......@@ -981,7 +982,6 @@ module.exports = (function() {
, sourceJoinOn
, targetJoinOn
, targetWhere
, throughWhere;
......@@ -1034,8 +1034,10 @@ module.exports = (function() {
if (include.where || include.through.where) {
if (include.where) {
targetWhere = self.getWhereConditions(include.where, self.sequelize.literal(self.quoteIdentifier(as)), include.model, whereOptions);
if (targetWhere) {
joinQueryItem += ' AND ' + targetWhere;
}
}
if (subQuery && include.required) {
if (!options.where) options.where = {};
(function (include) {
......@@ -1148,8 +1150,11 @@ module.exports = (function() {
subQueryJoinOn += ' = ' + self.quoteTable(tableRight) + '.' + self.quoteIdentifier(attrRight);
if (include.where) {
joinOn += ' AND ' + self.getWhereConditions(include.where, self.sequelize.literal(self.quoteIdentifier(as)), include.model, whereOptions);
subQueryJoinOn += ' AND ' + self.getWhereConditions(include.where, self.sequelize.literal(self.quoteIdentifier(as)), include.model, whereOptions);
targetWhere = self.getWhereConditions(include.where, self.sequelize.literal(self.quoteIdentifier(as)), include.model, whereOptions);
if (targetWhere) {
joinOn += ' AND ' + targetWhere;
subQueryJoinOn += ' AND ' + targetWhere;
}
}
// If its a multi association and the main query is a subquery (because of limit) we need to filter based on this association in a subquery
......
......@@ -2132,6 +2132,25 @@ describe(Support.getTestDialectTeaser('Include'), function() {
});
});
it('should work with an empty include.where', function () {
var User = this.sequelize.define('User', {})
, Company = this.sequelize.define('Company', {})
, Group = this.sequelize.define('Group', {});
User.belongsTo(Company);
User.belongsToMany(Group);
Group.belongsToMany(User);
return this.sequelize.sync({force: true}).then(function () {
return User.findAll({
include: [
{model: Group, where: {}},
{model: Company, where: {}}
]
});
});
});
it('should be able to order on the main table and a required belongsTo relation with custom tablenames and limit ', function () {
var User = this.sequelize.define('User', {
lastName: DataTypes.STRING
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!