You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Building a sample app with api-platform for backend, but lack of knowledge #501
Hi,
i'm playing with Api-Platform on a Sf4 project where the aim is to write our guidelines to build apps in my client company. At the beginning i just wanted to show how to build an hybrid SPA application. I say hybrid coz it's served by Sf4 instead of being fully standalone, but it will allows us to bring this in existing application. I was surprised by how easy it is to bring VueJS or React into Symfony.
But, now i'm facing a new problem : for a more complex demo with complex forms, i need to build an api so i choose ApiPlatform which seems to be really interesting.
I did a simple data model with books/authors/editors/series... which lead to ManyToOne and kindOf ManyToMany (but splitted into ManyToOne with associative tables to allow more properties in association). Now i don't really know how to setup the Api :-(
Why ? my GET routes have circular reference exception (Books is linked to ProjectBookCreation which is linked to Authors and... Books), and my PUT/POST routes doesn't have overloded methods that allow to post all required information : to PUT/POST a book i wish to post at the same time all authors and editors linked to that book...
If you have any information s that might help me to build quickly this part of the app that would be cool.
The project is here (branch orm-for-form-demo) : https://github.com/Rebolon/php-sf-flex-webpack-encore-vuejs/tree/feature/orm-for-form-demo
The README.md should be enough to start the project (everything is done with NPM).
I will certainly write a new article on medium once all is done, and i will promote all libs/technologies used, and all persons that helped me !
It's because the ProjectBookCreation is not marked with @ApiResource, so it's not handled by the API Platform (it is by the Symfony one), and as there is a circular reference, an error is thrown.
If ProjectBookCreation where an API resource, the circular reference would be handled automatically. If you don't want to make it a resource, you need to register a circular reference handler by yourself: https://symfony.com/doc/current/components/serializer.html#handling-circular-references
Reacted by Achilles Kaloeridis, anatholius, cve, Tobias Weichart, ma0dubois, VincentPaulinDatadome, Julien Manganne, Nikolai Plath, Vladyslav Alatortsev, Tobi Ogunleye and 8 more
Reacted by Nikolai Plath, Tobi Ogunleye, remif25 and Abdessamad (Almo) Idrissi
Reacted by Badr B., Nikolai Plath, Vladyslav Alatortsev, Tobi Ogunleye, Nikolay Deriglaozov and Abdessamad (Almo) Idrissi
I have just found this ! and another thing seems to write the getter for the identifier if i don't want to get Unable to generate an IRI for the item of type...
Thanks, just need now to writ specific PUT/POST route on Book entity to be able to add Editors and Authors at the same time
Activity
dunglas commentedon Dec 27, 2017
Hi,
Thanks for trying API Platform!
I don't get exactly the problem you have. API Platform handles circular references natively thanks to its hypermedia capabilities.
Can you copy the error you get?
Best regards,
Rebolon commentedon Dec 27, 2017
Here is one circular error when retreiving books from serie 1 : /api/series/1/books
dunglas commentedon Dec 28, 2017
It's because the
ProjectBookCreationis not marked with@ApiResource, so it's not handled by the API Platform (it is by the Symfony one), and as there is a circular reference, an error is thrown.If
ProjectBookCreationwhere an API resource, the circular reference would be handled automatically. If you don't want to make it a resource, you need to register a circular reference handler by yourself: https://symfony.com/doc/current/components/serializer.html#handling-circular-referencesRebolon commentedon Dec 28, 2017
I have just found this ! and another thing seems to write the getter for the identifier if i don't want to get
Unable to generate an IRI for the item of type...Thanks, just need now to writ specific PUT/POST route on Book entity to be able to add Editors and Authors at the same time
elvismdev commentedon Feb 2, 2019
@dunglas I'm having this same issue, with an
Orderentity that has a relationship withUserentity.Here part of my error:
Orderentity is marked with@ApiResourcebutUseris not. I don't need/want to makeUseran API resource, onlyOrder. It seems to me that I have to register a circular reference handler by myself following the symfony docs here: https://symfony.com/doc/current/components/serializer.html#handling-circular-referencesHowever, I'm a bit lost around how or where I should put the custom callable code following the example there:
Could you provide some more context or an example where that would go?
If that's useful, here are my
OrderandUserentities: