We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do you want to request a feature or report a bug? Bug
What is the current behavior? By cloning a schema the SchemaType loose the reference of the default requiredValidator method.
The error is related to this commit a0f6ac1
If the current behavior is a bug, please provide the steps to reproduce.
const mongoose = require('mongoose'); class Distance extends mongoose.SchemaType { //... } mongoose.Schema.Types.Distance = Distance; (async () => { const schema = new mongoose.Schema({ field: {type: Distance, required: true} }); // Test KO const TestKo = mongoose.model('TestKo', schema.clone()); //>> cloned const testKo = new TestKo(); await testKo.validate(); //>> KO, not throwing the ValidationError "Path `field` is required console.error('should not exec bottom'); // Test Ok const TestOk = mongoose.model('TestOk', schema); //>> not cloned const testOk = new TestOk(); await testOk.validate(); })();
What is the expected behavior? I expect the required validator to be executed after being cloned
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version. node v12.8.1 Mongoose v5.6.11
The text was updated successfully, but these errors were encountered:
test(schema): repro #8111
29b232e
50aeda0
fix(schema): improve fix for #8111
dba0336
Hi @vkarpov15 ,
Thanks for the fix!
As I worked on creating plugins with setters and getters I saw that when a SchemaType is cloned, we also loose its getters and setters.
Can you add these two lines in the clone method:
schematype.getters = this.getters.slice(); schematype.setters = this.setters.slice();
Kind regards
Sorry, something went wrong.
Add missing getters and setters copy when cloning (see issue Automatt…
9b8b7b3
…ic#8111)
Merge pull request #8124 from StphnDamon/hotfix/schematype-cloning
8625bb9
Add missing getters and setters copy when cloning (see issue #8111)
No branches or pull requests
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
By cloning a schema the SchemaType loose the reference of the default requiredValidator method.
The error is related to this commit a0f6ac1
If the current behavior is a bug, please provide the steps to reproduce.
What is the expected behavior?
I expect the required validator to be executed after being cloned
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
node v12.8.1
Mongoose v5.6.11
The text was updated successfully, but these errors were encountered: