Fix #1434 2.55.1 Throws when using where query against "JSON Object or ANY" Type (#1444)

* Test for JSON object or any type

* dao.js coercion type.definition existence check
This commit is contained in:
Shing 2017-07-29 04:30:49 +08:00 committed by Kevin Delisle
parent 29676f6510
commit 88771f10fc
2 changed files with 16 additions and 3 deletions

View File

@ -1610,9 +1610,12 @@ DataAccessObject._coerce = function(where, props) {
if (props[model]) {
var clause = {};
clause[prop] = where[p];
where[p] = Array.isArray(props[model].type) ?
self._coerce(clause, props[model].type[0].definition.properties)[prop] :
self._coerce(clause, props[model].type.definition.properties)[prop];
var type = Array.isArray(props[model].type) ? props[model].type[0] : props[model].type;
if (type && type.definition && type.definition.properties) {
where[p] = self._coerce(clause, type.definition.properties)[prop];
continue;
}
// else fall-back to old/default coercion
continue;
}

View File

@ -20,6 +20,7 @@ describe('crud-with-options', function() {
role: {type: String, index: true},
order: {type: Number, index: true, sort: true},
vip: {type: Boolean},
meta: {type: Object},
});
options = {};
filter = {fields: ['name', 'id']};
@ -259,6 +260,15 @@ describe('crud-with-options', function() {
});
});
it('should not throw for nested properties for ANY or Object type', function(done) {
User.find({where: {'meta.thisPropertyNotDefined': true}}, function(err, users) {
should.not.exists(err);
should.exists(users);
users.should.have.lengthOf(0);
done();
});
});
it('should allow find(filter, options)', function() {
User.find({limit: 3}, options);
});