-
Notifications
You must be signed in to change notification settings - Fork 639
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
Nested model validation #478
Comments
Same question for a different scenario: you want to validate model with different rule sets (for example, different rules for insert and update). One way is to use If validation is handled outside of the model, you can validate incoming data with different rule sets and use model just to insert or update after. Not sure, if this is possible with current model layer validation. |
After trying to implement this in objection, I think the best way to achieve this is by also adding your relations to |
@koskimas yeah, I ended up by moving validation away from model level and never had any issues :) |
I tried to use
insertGraph
method, but I'm not sure how to handle validation errors for nested models.For example
If
children
model has required field forlastName
and input value is not provided, I'd expect a nested error withchildren.0.lastName
.For current workaround I take input data, validate and then use model to save so validation is handled outside of the model.
This also led me to thoughts, if validation logic belongs to a model or a request layer. Shall we validate data first and then use model to save it or leave validation to model and improve nested validation.
I'm interested in recommended way of doing this since nested data validation is common and current ways of solving this.
The text was updated successfully, but these errors were encountered: