Fix the regexp value for like/nlike

This commit is contained in:
Raymond Feng 2015-07-02 23:22:36 -07:00
parent 62a429b2a6
commit 4206088fbc
2 changed files with 20 additions and 1 deletions

View File

@ -1183,7 +1183,10 @@ DataAccessObject._coerce = function (where) {
}
} else {
if (val != null) {
val = DataType(val);
if (!((operator === 'like' || operator === 'nlike') &&
val instanceof RegExp)) {
val = DataType(val);
}
}
}
// Rebuild {property: {operator: value}}

View File

@ -164,6 +164,14 @@ describe('Memory connector', function() {
});
});
it('should allow to find using like with regexp', function(done) {
User.find({where: {name: {like: /.*St.*/}}}, function(err, posts) {
should.not.exist(err);
posts.should.have.property('length', 2);
done();
});
});
it('should support like for no match', function(done) {
User.find({where: {name: {like: 'M%XY'}}}, function(err, posts) {
should.not.exist(err);
@ -180,6 +188,14 @@ describe('Memory connector', function() {
});
});
it('should allow to find using nlike with regexp', function(done) {
User.find({where: {name: {nlike: /.*St.*/}}}, function(err, posts) {
should.not.exist(err);
posts.should.have.property('length', 4);
done();
});
});
it('should support nlike for no match', function(done) {
User.find({where: {name: {nlike: 'M%XY'}}}, function(err, posts) {
should.not.exist(err);