Skip to content

Commit 074c26e

Browse files
committed
fix: fixed handling refPath with nested children
1 parent bf48a4a commit 074c26e

7 files changed

Lines changed: 1000 additions & 4 deletions

File tree

.idea/.gitignore

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/mongoose-id-validator.iml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/id-validator.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ IdValidator.prototype.validateSchema = function (
5252
}
5353
} else if (schemaType.options && schemaType.options.refPath) {
5454
refModelPath = schemaType.options.refPath
55+
console.log("[mongoose-id-validator] schemaType.options: ", schemaType.options)
56+
console.log("[mongoose-id-validator] schemaType: refPath", schemaType.options.refPath)
5557
if (schemaType.options.refConditions) {
5658
conditions = schemaType.options.refConditions
5759
}
@@ -91,9 +93,17 @@ IdValidator.prototype.validateSchema = function (
9193
})
9294
}
9395
var localRefModelName = refModelName
96+
/*console.log("[mongoose-id-validator] REF_PATH_NAME: ", refModelPath)
97+
console.log("[mongoose-id-validator] THIS: ", this)
98+
console.log("[mongoose-id-validator] SCHEMA: ", schemaType)
99+
console.log("[mongoose-id-validator] PATH: ", path)*/
100+
94101
if (refModelPath) {
95-
localRefModelName = this[refModelPath]
102+
const refModelPathSplits = refModelPath.split('.')
103+
if(refModelPathSplits.length > 1) localRefModelName = this[refModelPathSplits[refModelPathSplits.length-1]]
104+
else localRefModelName = this[refModelPath]
96105
}
106+
// console.log("[mongoose-id-validator] REF_Model_NAME: ", localRefModelName)
97107

98108
return validateFunction(this, connection, localRefModelName,
99109
value, conditionsCopy, resolve, reject, allowDuplicates)
@@ -123,6 +133,7 @@ function executeQuery (query, conditions, validateValue, resolve, reject) {
123133

124134
function validateId (
125135
doc, connection, refModelName, value, conditions, resolve, reject) {
136+
126137
if (value == null) {
127138
resolve(true)
128139
return

0 commit comments

Comments
 (0)