CampbellSoftwareSolutions / mongoose-id-validator

Mongoose plug in to validate ObjectID references point to valid existing documents.
Other
47 stars 26 forks source link

Support model ref and function ref #42

Closed LSafer closed 2 years ago

LSafer commented 2 years ago

Explanation

Mongoose allows the field ref to be any of:

Expected Behavior

When ref is a function, the plugin executes the function When ref is a model, the plugin takes the name of the model

Actual Behavior

The plugin uses the toString function the value on ref to get the collection name

LSafer commented 2 years ago
    /**
     * The model that `populate()` should use if populating this path.
     */
    ref?: string | Model<any> | ((this: any, doc: any) => string | Model<any>);
LSafer commented 2 years ago

https://github.com/trovafer/mongoose-id-validator/pull/1

LSafer commented 2 years ago

https://github.com/LSafer/mongoose-id-validator/tree/patch-1

LSafer commented 2 years ago

https://github.com/CampbellSoftwareSolutions/mongoose-id-validator/pull/41

LSafer commented 2 years ago

Never mind, I created https://github.com/lsafer/mongoose-extra-validators to address the issue.