douzai1074 2017-06-06 13:42
浏览 102
已采纳

Doctrine映射问题 - 在null上调用成员函数setValue()

I have a weird issue with Doctrine. I have set up the following structure:

/**
 * @ORM\Entity
 * @ORM\Table(name="fp_credit_returned_product")
 */
class ReturnedProduct {
...
    /**
     * @var FpCredit\Models\Credit\ReturnedProductDetail
     * @ORM\OneToMany(targetEntity="\FpCredit\Models\Credit\ReturnedProductDetail", mappedBy="returned_product", cascade={"persist"})
     */
    private $details;

public function getDetails() {
    return $this->details;
}

public function setDetails($details) {
    $this->details = $details;
}   

and:

/**
 * @ORM\Entity
 * @ORM\Table(name="fp_credit_returned_product_detail")
 */
class ReturnedProductDetail {

     /**
     * @var FpCredit\Models\Credit\ReturnedProduct
     * @ORM\ManyToOne(targetEntity="\FpCredit\Models\Credit\ReturnedProduct")
     * @ORM\JoinColumn(name="returned_product_id", nullable=false, referencedColumnName="id")
     */
    private $returnedProduct;

    public function getReturnedProduct() {
        return $this->returnedProduct;
    }

    public function setReturnedProduct($returnedProduct) {
        $this->returnedProduct = $returnedProduct;
    }

Then I query all returnedProducts and do the following:

foreach ($errorLogs as $eLog) {
    $errorDetails = $eLog->getDetails();
    if ($errorDetails) {
        foreach ($errorDetails as $errorDetail) {

            $errorArticle = $errorDetail->getArticle();
        }
    }
}

Because of the $errorDetail->getArticle() I get this error:

PHP Fatal error:  Call to a member function setValue() on null in /var/www/html/vendor/doctrine/orm/lib/Doctrine/ORM/PersistentCollection.php

Does anybody know why this error occurs and how I can fix it? Is something wrong with my mapping? One ReturnedProducts has several ReturnProductDetails.

Thanks for your help!

  • 写回答

1条回答 默认 最新

  • doutun1362 2017-06-06 13:46
    关注

    Can you try in your class ReturnedProduct

    mappedBy="returnedProduct" 
    

    regards.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计