简体   繁体   中英

"hydra:description": "A circular reference has been detected when serializing the object of class \"App\\Entity\\Category\" (configured limit: 1).",

I am using Api platform and Symfony 5.4, ManyTomany relation on category and I have this error

I found the solution: by adding @ApiResource on the Category entity.

It's because the Category 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 Category 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

Source: https://github.com/api-platform/api-platform/issues/501

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM