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

Commit 491192f9 by Mick Hansen

Merge pull request #2124 from meetearnest/emptyarr

fix {where: []} causing finds to crash if model is paranoid
2 parents b2b0e6b6 c4020dda
Showing with 23 additions and 2 deletions
...@@ -1598,12 +1598,14 @@ module.exports = (function() { ...@@ -1598,12 +1598,14 @@ module.exports = (function() {
var whereObj = {}; var whereObj = {};
whereObj[quoteIdentifiedDeletedAtCol] = null; whereObj[quoteIdentifiedDeletedAtCol] = null;
options.where.push(whereObj); options.where.push(whereObj);
} else { } else if (options.where.length) {
// Don't overwrite our explicit deletedAt search value if we provide one
if (options.where[0].indexOf(deletedAtCol) !== -1) { if (options.where[0].indexOf(deletedAtCol) !== -1) {
return options; return options;
} }
// Don't overwrite our explicit deletedAt search value if we provide one
options.where[0] += ' AND ' + quoteIdentifiedDeletedAtCol + ' IS NULL '; options.where[0] += ' AND ' + quoteIdentifiedDeletedAtCol + ' IS NULL ';
} else {
options.where[0] = quoteIdentifiedDeletedAtCol + ' IS NULL ';
} }
} else { } else {
options.where[deletedAtCol] = null; options.where[deletedAtCol] = null;
......
...@@ -642,6 +642,25 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () { ...@@ -642,6 +642,25 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
}) })
}) })
}) })
it('should not fail if model is paranoid and where is an empty array', function(done) {
var User = this.sequelize.define('User', { username: Sequelize.STRING }, { paranoid: true })
User.sync({ force: true })
.then(function () {
return User.create({ username: 'A fancy name' })
})
.then(function(u) {
return User.find({ where: [] })
})
.then(function (u) {
expect(u.username).to.equal('A fancy name')
done();
})
.catch(function (err) {
done(err)
})
})
}) })
describe('findOrInitialize', function() { describe('findOrInitialize', function() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!