Skip to content

Commit

Permalink
Merge pull request #36 from makinde/array_schema_fix
Browse files Browse the repository at this point in the history
More robust check for if schemaType path is an array
  • Loading branch information
martin-css authored Dec 2, 2019
2 parents 4c7a722 + 6a8e576 commit 40f9a1b
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/id-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,28 @@ IdValidator.prototype.validateSchema = function (
var validateFunction = null
var refModelName = null
var conditions = {}
var optionsSource = null

if (schemaType.options && schemaType.options.ref) {
validateFunction = validateId
refModelName = schemaType.options.ref
if (schemaType.options.refConditions) {
conditions = schemaType.options.refConditions
}
} else if (schemaType.caster && schemaType.caster.instance &&
schemaType.caster.options && schemaType.caster.options.ref) {
validateFunction = validateIdArray
refModelName = schemaType.caster.options.ref
if (schemaType.caster.options.refConditions) {
conditions = schemaType.caster.options.refConditions
}
}

if (validateFunction) {
var isArraySchemaType =
(schemaType.caster && schemaType.caster.instance) ||
(schemaType.instance === 'Array') ||
(schemaType['$isMongooseArray'] === true)
validateFunction = isArraySchemaType ? validateIdArray : validateId

if (refModelName) {
schema.path(path).validate({
validator: function (value) {
return new Promise(function (resolve, reject) {
Expand Down

0 comments on commit 40f9a1b

Please sign in to comment.