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.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题