简体   繁体   English

JMSSerializer软件包-循环引用错误(仅在Prod Azure环境上)-Symfony4 / Doctrine2 REST API

[英]JMSSerializer Bundle - Circular Reference Error (Only on Prod Azure Environment) - Symfony4/Doctrine2 REST API

So I know somewhat similar issues have been discussed numerous times before but I haven't had any luck finding a solution with this specific issue. 因此,我知道以前曾经多次讨论过类似的问题,但是我没有运气为这个特定问题找到解决方案。

Running locally (using MAMP) I have no issues with my API responses. 在本地运行(使用MAMP),我的API响应没有问题。 However once deployed to the production Azure server (via Ansible) I run into the dreaded error: 但是,一旦(通过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

I'm confident that all of my doctrine associations are setup correctly yet something is triggering an infinite loop. 我相信我所有的学说关联都已正确设置,但是某些事件触发了无限循环。

Here is a simplified entity relationship and the main associations from within my doctrine classes. 这是我的学说课中的简化实体关系和主要关联。

Any comments or help would be greatly suggested - many thanks! 任何意见或帮助将被强烈建议-非常感谢!

Plan -> (hasMany) Bundle -> (hasMany) -> Product 计划->(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;
}

Use @Exclude annotation like that: 像这样使用@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.

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