diff --git a/lib/id-validator.js b/lib/id-validator.js index 9794131..a711a9f 100644 --- a/lib/id-validator.js +++ b/lib/id-validator.js @@ -41,6 +41,7 @@ IdValidator.prototype.validateSchema = function ( var validateFunction = null var refModelName = null + var refModelPath = null var conditions = {} var optionsSource = null @@ -49,6 +50,11 @@ IdValidator.prototype.validateSchema = function ( if (schemaType.options.refConditions) { conditions = schemaType.options.refConditions } + } else if (schemaType.options && schemaType.options.refPath) { + refModelPath = schemaType.options.refPath + if (schemaType.options.refConditions) { + conditions = schemaType.options.refConditions + } } else if (schemaType.caster && schemaType.caster.instance && schemaType.caster.options && schemaType.caster.options.ref) { refModelName = schemaType.caster.options.ref @@ -63,7 +69,7 @@ IdValidator.prototype.validateSchema = function ( (schemaType['$isMongooseArray'] === true) validateFunction = isArraySchemaType ? validateIdArray : validateId - if (refModelName) { + if (refModelName || refModelPath) { schema.path(path).validate({ validator: function (value) { return new Promise(function (resolve, reject) { @@ -84,8 +90,12 @@ IdValidator.prototype.validateSchema = function ( } }) } + var localRefModelName = refModelName + if (refModelPath) { + localRefModelName = this[refModelPath] + } - return validateFunction(this, connection, refModelName, + return validateFunction(this, connection, localRefModelName, value, conditionsCopy, resolve, reject, allowDuplicates) } resolve(true)