Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JMSSerializer捆绑包-循环引用错误(仅在Prod Azure环境上)-Symfony4/Doctrine2 REST API_Api_Doctrine Orm_Symfony4_Jmsserializerbundle - Fatal编程技术网

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

JMSSerializer捆绑包-循环引用错误(仅在Prod Azure环境上)-Symfony4/Doctrine2 REST API,api,doctrine-orm,symfony4,jmsserializerbundle,Api,Doctrine Orm,Symfony4,Jmsserializerbundle,所以我知道类似的问题以前已经讨论过很多次了,但我没有找到解决这个具体问题的方法 在本地运行(使用MAMP),我的API响应没有问题。但是,一旦部署到生产Azure服务器(通过Ansible),我就会遇到可怕的错误: request.CRITICAL:未捕获的PHP异常Symfony\Component\Serializer\Exception\CircularReferenceException:“序列化类”App\ServiceProviderBundle\Entity\Plan的对象时检测到

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

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

request.CRITICAL:未捕获的PHP异常Symfony\Component\Serializer\Exception\CircularReferenceException:“序列化类”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;
}

你好,尼基塔,谢谢你回复我。我一直在默认情况下排除所有内容,并使用@Expose添加我需要的属性。我想我已经发现了这个问题——JMSSerializerBundle没有为“prod”环境启用。我会在5分钟内知道一旦虚拟机启动。。。