简体   繁体   English

"hydra:description": "在序列化 class \"App\\Entity\\Category\" 的 object 时检测到循环引用(配置限制:1)。",

[英]"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我正在使用 Api 平台和 Symfony 5.4,类别上的 ManyTomany 关系,我有这个错误

I found the solution: by adding @ApiResource on the Category entity.我找到了解决方案:通过在 Category 实体上添加 @ApiResource 。

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.是因为Category没有标注@ApiResource,所以没有被API平台处理(是Symfony平台),因为存在循环引用,所以会报错。 If Category where an API resource, the circular reference would be handled automatically.如果类别中有 API 资源,循环引用将自动处理。 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如果你不想让它成为一个资源,你需要自己注册一个循环引用处理器: https://symfony.com/doc/current/components/serializer.html#handling-circular-references

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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