@@ -8,6 +8,7 @@ const modify = require('./modify').check;
88 * Create a new modelate, validating all properties
99 * Options might be:
1010 * - model: {Object} A model to use (instead of this.modelName)
11+ * - modelName: {String} A name for the model to use (instead of this.modelName)
1112 * @param data {Object} The data to validate
1213 * @param opts {Object} Options for the modelate.
1314 */
@@ -17,11 +18,13 @@ function modelate(data, opts) {
1718 error : null
1819 }
1920
20- if ( ( ! this . modelName && ! ( opts && ! opts . model ) ) || ! data || typeof data !== 'object' ) {
21+ if ( ( ! this . modelName && ( ! ( opts && ! opts . model ) || ! ( opts && ! opts . modelName ) ) ) || ! data || typeof data !== 'object' ) {
2122 return modelateResponse ;
2223 }
2324
24- const model = ( opts && opts . model ) || models [ this . modelName ] ;
25+ var modelName = ( opts && opts . modelName ) || this . modelName ;
26+
27+ const model = ( opts && opts . model ) || models [ modelName ] ;
2528 const result = util . clone ( model ) || { } ;
2629 const errors = [ ] ;
2730
@@ -30,7 +33,7 @@ function modelate(data, opts) {
3033 data [ prop ] = modify ( data [ prop ] , model [ prop ] ) ;
3134
3235 // Step 2: validate the result
33- if ( validate ( data [ prop ] , model [ prop ] , errors , this . modelName , prop ) ) {
36+ if ( validate ( data [ prop ] , model [ prop ] , errors , modelName , prop ) ) {
3437 result [ prop ] = data [ prop ] ;
3538 } else {
3639 delete result [ prop ] ;
0 commit comments