Skip to content

Commit

Permalink
Fix: error when saving existing model and changing all keys
Browse files Browse the repository at this point in the history
  • Loading branch information
bsiddiqui committed May 31, 2017
1 parent 9e6e210 commit 4f1043a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ module.exports = function modelBase (bookshelf, params) {
var presentKeys = Object.keys(attrs)
var optionalKeys = difference(schemaKeys, presentKeys)
// only validate the keys that are being updated
validation = Joi.validate(attrs, this.validate.optionalKeys(optionalKeys))
validation = Joi.validate(
attrs,
optionalKeys.length
// optionalKeys() doesn't like empty arrays
? this.validate.optionalKeys(optionalKeys)
: this.validate
)
} else {
validation = Joi.validate(this.attributes, this.validate)
}
Expand Down

0 comments on commit 4f1043a

Please sign in to comment.