[英]JMSSerializer Bundle - Circular Reference Error (Only on Prod Azure Environment) - Symfony4/Doctrine2 REST API
因此,我知道以前曾经多次讨论过类似的问题,但是我没有运气为这个特定问题找到解决方案。
在本地运行(使用MAMP),我的API响应没有问题。 但是,一旦(通过Ansible)部署到生产Azure服务器中,我就会遇到可怕的错误:
request.CRITICAL: Uncaught PHP Exception Symfony\\Component\\Serializer\\Exception\\CircularReferenceException: "A circular reference has been detected when serializing the object of class "App\\ServiceProviderBundle\\Entity\\Plan
我相信我所有的学说关联都已正确设置,但是某些事件触发了无限循环。
这是我的学说课中的简化实体关系和主要关联。
任何意见或帮助将被强烈建议-非常感谢!
计划->(hasMany)捆绑商品->(hasMany)->产品
class Plan {
/**
* @ORM\OneToMany(targetEntity="App\ServiceProviderBundle\Entity\Bundle", mappedBy="plan")
*/
private $bundles;
}
class Bundle {
/**
* @ORM\ManyToOne(targetEntity="App\ServiceProviderBundle\Entity\Plan", inversedBy="bundles")
* @ORM\JoinColumn(nullable=true)
*/
private $plan;
/**
* @SerializedName("products")
* @ORM\OneToMany(targetEntity="App\ServiceProviderBundle\Entity\BundleProduct", mappedBy="bundle",
* cascade={"persist", "remove"})
* @ORM\JoinColumn(nullable=false)
*/
private $bundleProducts;
}
class BundleProduct {
/**
* @ORM\ManyToOne(targetEntity="App\ServiceProviderBundle\Entity\Bundle", inversedBy="bundleProducts")
* @ORM\JoinColumn(nullable=false)
*/
private $bundle;
}
像这样使用@Exclude
注释:
class BundleProduct {
/**
* @ORM\ManyToOne(targetEntity="App\ServiceProviderBundle\Entity\Bundle", inversedBy="bundleProducts")
* @ORM\JoinColumn(nullable=false)
* @Exclude
*/
private $bundle;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.