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

Validation is not being enforced #57

Closed
gunar opened this issue May 22, 2017 · 7 comments
Closed

Validation is not being enforced #57

gunar opened this issue May 22, 2017 · 7 comments
Assignees
Labels

Comments

@gunar
Copy link

gunar commented May 22, 2017

Hi, is there a way to make sure ForestAdmin adheres to my models' custom validators?

I thought this should work out-of-the-box since this is a mongoose plugin, not just mongo.

For example, I have a validation that makes sure codes are unique across three collections.

Thank you for ForestAdmin. Love it!
Don't know how nobody thought of it before.

@arnaudbesnier
Copy link
Member

Hi @gunar, validation is not something the current liana manage properly.
We definitely want to improve this, in the future releases.

As you may notice, we have a PR in review to support simple validations here: #35

But you seem to have complex validations. We would love to have a small example of your complex validation to help us implement it.

🌲🌲🌲

@gunar
Copy link
Author

gunar commented May 23, 2017

Hi @arnaudbesnier
Thanks for the quick response

Why it is needed to implement code for validation?
If you take my model and do instance.save() it will throw, in case of validation errors
Isn't that what forest-express-mongoose does?

@arnaudbesnier
Copy link
Member

@gunar sorry for the misunderstanding... The PR I showed you is a feature to improve the validation experience.

You are right, as the liana is based on the Mongoose ORM. It means that the validations you defined in your models should work while using Forest.
If I understand well, you are submitting an issue here, right?
Your custom validations are simply not executed or do you notice another unexpected behaviour?

Can you provide a simple code example based on your code, that we could use to reproduce the issue?

@gunar
Copy link
Author

gunar commented May 28, 2017

Thank you for the feedback
Here's the code https://github.com/gunar/forestRepro
Validators are not being checked on updates (only on inserts, it seems)

Validator on insert works

Create
bitcoin.code = 'ZZZ'
Then try to create
litecoin.code = 'ZZZ'
I get a validation error

Validator on update does not work

Create
bitcoin.code = 'ZZZ'
litecoin.code = 'ZZA'
Then update
litecoin.code = 'ZZZ'
I get no validation error, but should have

@arnaudbesnier
Copy link
Member

@gunar Ok I think I found the reason why the validations are not triggered on record update. I think the method findByIdAndUpdate (https://github.com/ForestAdmin/forest-express-mongoose/blob/devel/services/resource-updater.js#L19) needs to have the runValidators option set to true which is not the case.

Let me reproduce and fix this week.

@arnaudbesnier
Copy link
Member

@gunar can you check if the PR fixes your issue?

@arnaudbesnier
Copy link
Member

The fix has been release in the 1.1.5 liana version. Here are the changelogs.

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

No branches or pull requests

2 participants