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

查看:21
本文介绍了JMSSerializer Bundle - 循环引用错误(仅限 Prod Azure 环境) - Symfony4/Doctrine2 REST API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

request.CRITICAL: Uncaught PHP Exception Symfony\Component\Serializer\Exception\CircularReferenceException: "在序列化类 "App\ServiceProviderBundle\Entity\Plan 的对象时检测到循环引用>

我确信我所有的教义关联都已正确设置,但有些东西正在触发无限循环.

这是一个简化的实体关系以及我的教义类中的主要关联.

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

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

课程计划{/*** @ORM\OneToMany(targetEntity="App\ServiceProviderBundle\Entity\Bundle",mappedBy="plan")*/私人 $bundle;}类捆绑{/*** @ORM\ManyToOne(targetEntity="App\ServiceProviderBundle\Entity\Plan", inversedBy="bundles")* @ORM\JoinColumn(nullable=true)*/私人$计划;/*** @SerializedName("产品")* @ORM\OneToMany(targetEntity="App\ServiceProviderBundle\Entity\BundleProduct", mappingBy="bundle",* 级联={坚持",删除"})* @ORM\JoinColumn(nullable=false)*/私人 $bundleProducts;}类捆绑产品{/*** @ORM\ManyToOne(targetEntity="App\ServiceProviderBundle\Entity\Bundle", inversedBy="bundleProducts")* @ORM\JoinColumn(nullable=false)*/私人 $bundle;}

解决方案

像这样使用@Exclude注解:

class BundleProduct {/*** @ORM\ManyToOne(targetEntity="App\ServiceProviderBundle\Entity\Bundle", inversedBy="bundleProducts")* @ORM\JoinColumn(nullable=false)* @排除*/私人 $bundle;}

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

解决方案

Use @Exclude annotation like that:

class BundleProduct {

    /**
     * @ORM\ManyToOne(targetEntity="App\ServiceProviderBundle\Entity\Bundle", inversedBy="bundleProducts")
     * @ORM\JoinColumn(nullable=false)
     * @Exclude
     */
    private $bundle;
}

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

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