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

Commit 8683d792 by Ryan Pon

check how to treat array when doing paranoidClause

1 parent 9d774d31
Showing with 30 additions and 5 deletions
...@@ -1580,12 +1580,23 @@ module.exports = (function() { ...@@ -1580,12 +1580,23 @@ module.exports = (function() {
options.where += ' AND ' + quoteIdentifiedDeletedAtCol + ' IS NULL '; options.where += ' AND ' + quoteIdentifiedDeletedAtCol + ' IS NULL ';
} }
else if (Array.isArray(options.where)) { else if (Array.isArray(options.where)) {
// Need to check how the array is being used, as it could be an array
// Don't overwrite our explicit deletedAt search value if we provide one // of string-likes/Dates or an array with objects, hashes, or other
if (options.where[0].indexOf(deletedAtCol) !== -1) { // complex data types
return options; if (Utils.canTreatArrayAsAnd(options.where)) {
// TODO: This is simplifying this case greatly. We actually need all
// the logic from QueryGenerator.getWhereConditions in order to
// properly decide what to do here.
var whereObj = {};
whereObj[quoteIdentifiedDeletedAtCol] = null;
options.where.push(whereObj);
} else {
// Don't overwrite our explicit deletedAt search value if we provide one
if (options.where[0].indexOf(deletedAtCol) !== -1) {
return options;
}
options.where[0] += ' AND ' + quoteIdentifiedDeletedAtCol + ' IS NULL ';
} }
options.where[0] += ' AND ' + quoteIdentifiedDeletedAtCol + ' IS NULL ';
} else { } else {
options.where[deletedAtCol] = null; options.where[deletedAtCol] = null;
} }
......
...@@ -2100,6 +2100,20 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () { ...@@ -2100,6 +2100,20 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
}) })
}) })
it('should not fail when array contains Sequelize.or / and', function (done) {
this.User.findAll({
where: [
this.sequelize.or({ username: 'vader' }, { username: 'luke' }),
this.sequelize.and({ id: [1, 2, 3] })
]
})
.then(function(res) {
expect(res).to.have.length(2)
done()
})
.catch(function(e) { done(e) })
})
it('should not fail with an include', function(done) { it('should not fail with an include', function(done) {
this.User.findAll({ this.User.findAll({
where: [ where: [
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!