JMSSerializerbundle-循环引用错误(仅在Prod Azure环境上)-Symfony4/Doctrine2



所以我知道类似的问题以前已经讨论过很多次了,但我没有找到解决这个特定问题的方法。

本地运行(使用MAMP(我的API响应没有问题。然而,一旦部署到生产Azure服务器(通过Ansible(,我就会遇到可怕的错误:

request.CRITICAL: Uncaught PHP Exception SymfonyComponentSerializerExceptionCircularReferenceException: "A circular reference has been detected when serializing the object of class "AppServiceProviderBundleEntityPlan

我相信我所有的学说关联都是正确设置的,但有些东西正在触发一个无限循环。

这是一个简化的实体关系和我的学说类中的主要关联。

任何意见或帮助都将被强烈建议-非常感谢!

计划->(hasMany(捆绑包->(hasMany(->产品

class Plan {
/**
* @ORMOneToMany(targetEntity="AppServiceProviderBundleEntityBundle", mappedBy="plan")
*/
private $bundles;
}

class Bundle {
/**
* @ORMManyToOne(targetEntity="AppServiceProviderBundleEntityPlan", inversedBy="bundles")
* @ORMJoinColumn(nullable=true)
*/
private $plan;
/**
* @SerializedName("products")
* @ORMOneToMany(targetEntity="AppServiceProviderBundleEntityBundleProduct", mappedBy="bundle",
*     cascade={"persist", "remove"})
* @ORMJoinColumn(nullable=false)
*/
private $bundleProducts;
}

class BundleProduct {
/**
* @ORMManyToOne(targetEntity="AppServiceProviderBundleEntityBundle", inversedBy="bundleProducts")
* @ORMJoinColumn(nullable=false)
*/
private $bundle;
}

使用类似的@Exclude注释:

class BundleProduct {
/**
* @ORMManyToOne(targetEntity="AppServiceProviderBundleEntityBundle", inversedBy="bundleProducts")
* @ORMJoinColumn(nullable=false)
* @Exclude
*/
private $bundle;
}

最新更新