Allow toObject() to accept an 'options' argument

This commit is contained in:
Raymond Feng 2018-05-10 10:13:14 -07:00
parent 4aa51e9956
commit 90163ba709
2 changed files with 8 additions and 2 deletions

View File

@ -418,6 +418,12 @@ ModelBaseClass.toString = function() {
* @returns {Object} returns Plain JSON object
*/
ModelBaseClass.prototype.toObject = function(onlySchema, removeHidden, removeProtected) {
if (typeof onlySchema === 'object' && onlySchema != null) {
var options = onlySchema;
onlySchema = options.onlySchema;
removeHidden = options.removeHidden;
removeProtected = options.removeProtected;
}
if (onlySchema === undefined) {
onlySchema = true;
}

View File

@ -133,8 +133,8 @@ describe('ModelBuilder', function() {
// Predefined property bio should be kept
user.toObject().should.have.property('bio', 'me');
user.toObject(true).should.have.property('bio', 'me');
user.toObject(false).should.have.property('bio', 'me');
user.toObject({onlySchema: true}).should.have.property('bio', 'me');
user.toObject({onlySchema: false}).should.have.property('bio', 'me');
done(null, User);
});