JMSSerializer软件包-循环引用错误(仅在Prod Azure环境上)-Symfony4/Doctrine2 REST API [英] JMSSerializer Bundle - Circular Reference Error (Only on Prod Azure Environment) - Symfony4/Doctrine2 REST API

查看:97
本文介绍了JMSSerializer软件包-循环引用错误(仅在Prod Azure环境上)-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.

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

Running locally (using MAMP) I have no issues with my API responses. However once deployed to the production Azure server (via Ansible) I run into the dreaded error:

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

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;
}

这篇关于JMSSerializer软件包-循环引用错误(仅在Prod Azure环境上)-Symfony4/Doctrine2 REST API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆