Skip to content
New issue

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

Is it possible to NOT have this plugin run when doing a model.validate()? #19

Open
lee-1ststop opened this issue Apr 25, 2018 · 4 comments

Comments

@lee-1ststop
Copy link

lee-1ststop commented Apr 25, 2018

Is it possible to NOT have this plugin run when doing a model.validate(), and only make it run on a save method? I'm using the model to carry out primary validation of an object before carrying out separate rules based validation. If both validation steps pass, then I save the entry into the DB. In this setup, the autoinc entries in the DB count up in 2's rather tha 1's.

@lee-1ststop lee-1ststop changed the title IS it possible to NOT have this plugin run when doing a model.validate(), and only make it run on a save method? I'm using the model to carry out primary validation of an object before carrying out separate rules based validation. If both validation steps pass, then I save the entry into the DB. Is it possible to NOT have this plugin run when doing a model.validate(), and only make it run on a save method? I'm using the model to carry out primary validation of an object before carrying out separate rules based validation. If both validation steps pass, then I save the entry into the DB. Apr 25, 2018
@lee-1ststop lee-1ststop changed the title Is it possible to NOT have this plugin run when doing a model.validate(), and only make it run on a save method? I'm using the model to carry out primary validation of an object before carrying out separate rules based validation. If both validation steps pass, then I save the entry into the DB. Is it possible to NOT have this plugin run when doing a model.validate(), and only make it run on a save method? I'm using the model to carry out primary validation of an object before carrying out separate rules based validation. If both validation steps pass, then I save the entry into the DB. In this setup, the autoinc entries in the DB count up in 2's rather tha 1's. Apr 25, 2018
@lee-1ststop lee-1ststop changed the title Is it possible to NOT have this plugin run when doing a model.validate(), and only make it run on a save method? I'm using the model to carry out primary validation of an object before carrying out separate rules based validation. If both validation steps pass, then I save the entry into the DB. In this setup, the autoinc entries in the DB count up in 2's rather tha 1's. Is it possible to NOT have this plugin run when doing a model.validate()? Apr 25, 2018
@nodkz
Copy link
Owner

nodkz commented Apr 25, 2018

Yep it possible via internal property __maiRunOnce

const alreadyGetId = doc.__maiRanOnce === true;

Before first valudation set it to true. And after that sdt it back to false.

Anyway it will be nice if this feature will be avaliable via public API. Any suggestions about how it should be?

@bigdong89
Copy link

fix bug: no support model validation
https://github.com/bigdong89/mongoose-plugin-autoinc

@nodkz
Copy link
Owner

nodkz commented Jun 14, 2018

@bigdong89 can you make PR where pre or post validation will work via some configuration option.

Thanks.

@bigdong89
Copy link

I package changed one as my own plugin in my product.
So some package info are changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants