fix: ignore extra properties when strict=filter (#1423)

Fix for #1422
This commit is contained in:
Tom Kirkpatrick 2018-08-30 04:57:37 +02:00 committed by Janny
parent 2b8b6719a7
commit 251798c711
3 changed files with 16 additions and 2 deletions

View File

@ -93,7 +93,7 @@ function applyStrictCheck(model, strict, data, inst, cb) {
key = keys[i];
if (props[key]) {
result[key] = data[key];
} else if (strict) {
} else if (strict && strict !== 'filter') {
inst.__unknownProperties.push(key);
}
}

View File

@ -633,6 +633,20 @@ describe('manipulation', function() {
});
});
it('should remove unknown attributes when strict: filter',
function(done) {
Person.definition.settings.strict = 'filter';
Person.findById(person.id, function(err, p) {
if (err) return done(err);
p.updateAttributes({name: 'John', foo: 'bar'},
function(err, p) {
if (err) return done(err);
p.should.not.have.property('foo');
done();
});
});
});
// Prior to version 3.0 `strict: true` used to silently remove unknown properties,
// now return validationError upon unknown properties
it('should return error on unknown attributes when strict: true',

View File

@ -73,7 +73,7 @@ describe('Model class inheritance', function() {
relations: {patch: true},
};
// saving original getMergePolicy method
// saving original getMergePolicy method
let originalGetMergePolicy = base.getMergePolicy;
// the injected getMergePolicy method captures the provided configureModelMerge option