For more deep advanced learning and understanding of lower level of it you can look at our REST courses. The packages we're using in the REST courses should be compatible with Symfony 5 already, but if you find a problem during following the course - please, let us know in comments below and we will try to help you!
Hi guys, I'm using this wonderful tuto to build an app. I have a question about returning an error on a oneToMany relation. I have the error returned but with no field name, just with a 0 index and as a string. Have you got any idea?
Hmm. That's a great question :). Are you using a CollectionType? In the eyes of the form component, if you have 3 of these things, then they are added to the form as indexes (e.g. form.products[0], form.products[1] and form.products[2]). Then, the errors are attached at the same "nodes".
So, there *is* certainly a way to take the index (e.g. 0) and find the correct thing (e.g. Product) that it's referring to. What exactly do you want to accomplish? And what does your API endpoint look like? Because, for example, if your user is sending an array of Product objects (via JSON), then communicating the index (e.g. 0) *is* the best way to tell them which has a validation error. But I'm guessing your situation is probably not exactly this :).
Cheers!
Was this comment helpful?
|
Share Comment
"Houston: no signs of life" Start the conversation!
This tutorial uses an older version of Symfony. The concepts of REST and errors are still valid, but I recommend using API Platform in new Symfony apps.
4 Comments
Is this course of REST good for symfony 5? Should i learn it? Or avoid it?
Hey Simon,
We do recommend to start with API Platform course, it's easier to learn and understand, and has Symfony 5 support. You can find a few courses about it here:
https://symfonycasts.com/sc...
https://symfonycasts.com/sc...
For more deep advanced learning and understanding of lower level of it you can look at our REST courses. The packages we're using in the REST courses should be compatible with Symfony 5 already, but if you find a problem during following the course - please, let us know in comments below and we will try to help you!
I hope this helps!
Cheers!
Hi guys,
I'm using this wonderful tuto to build an app. I have a question about returning an error on a oneToMany relation. I have the error returned but with no field name, just with a 0 index and as a string. Have you got any idea?
Hey julien moulis!
Hmm. That's a great question :). Are you using a CollectionType? In the eyes of the form component, if you have 3 of these things, then they are added to the form as indexes (e.g. form.products[0], form.products[1] and form.products[2]). Then, the errors are attached at the same "nodes".
So, there *is* certainly a way to take the index (e.g. 0) and find the correct thing (e.g. Product) that it's referring to. What exactly do you want to accomplish? And what does your API endpoint look like? Because, for example, if your user is sending an array of Product objects (via JSON), then communicating the index (e.g. 0) *is* the best way to tell them which has a validation error. But I'm guessing your situation is probably not exactly this :).
Cheers!
"Houston: no signs of life"
Start the conversation!