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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?