不能对我的一个实体使用 Doctrine PersistentCollection,另一个我可以
2022-08-30 21:21:00
我有一对协会。它们是多对多的,我使用显式创建的实体来加入它们,以便我可以获得有关关系的元数据。虽然它们是相同的,但一个有效,另一个不起作用。更糟糕的是,上周,他们都工作了,从那以后我就再也没有碰过他们。在MuSQL Workbench中,我可以选择正确的数据。
当我将数据提取到数组中时,生活是美好的。当我尝试另一个时,我得到:
对非对象上的成员函数的调用
setValue()
当我尝试它,访问它()或迭代它()时,我也会得到它。count()
$blah[0]
foreach
当我执行时:
echo get_class($inData)."<BR>";
echo get_class($inData->accountPurchaseNodes)."<BR>";
echo get_class($inData->accountPurchaseNodes[0])."<BR>";
echo "<HR>";
echo get_class($inData)." x<BR>";
echo get_class($inData->purchaseOrderNodes)."<BR>";
echo get_class($inData->purchaseOrderNodes[0])."<BR>";
echo "<HR>";
exit;
我得到:
GE\Entity\Purchase
Doctrine\ORM\PersistentCollection
GE\Entity\AccountPurchaseNode
GE\Entity\Purchase
Doctrine\ORM\PersistentCollection
( ! ) Fatal error: Call to a member function setValue() on a non-object in
/Users/tqwhite/Documents/webdev/goodEarth/goodearth.com/library/
Doctrine/ORM/PersistentCollection.php on line 168
下面,我将包括实体定义的相关部分。我已经花费了几个小时尝试这个和那个。我将非常感谢您的建议。
这个有效:
//==Purchase Entity=====================================
/**
* @param \Doctrine\Common\Collections\Collection $property
* @OneToMany(targetEntity="AccountPurchaseNode", mappedBy="account", cascade={"persist", "remove"});
*/
private $accountPurchaseNodes;
//in __construct()
$this->accountPurchaseNodes = new \Doctrine\Common\Collections\ArrayCollection();
//==AccountPurchaseNode Entity=====================================
/**
*
* @ManyToOne(targetEntity="Purchase", cascade={"all"}, fetch="EAGER")
* @JoinColumn(name="purchaseRefId", referencedColumnName="refId")
*
**/
private $purchase;
/**
*
* @ManyToOne(targetEntity="Account", cascade={"all"}, fetch="EAGER")
* @JoinColumn(name="accountRefId", referencedColumnName="refId")
*
**/
private $account;
//==Account Entity=====================================
/**
* @param \Doctrine\Common\Collections\Collection $property
* @OneToMany(targetEntity="AccountPurchaseNode", mappedBy="purchase", cascade={"persist", "remove"});
*/
private $accountPurchaseNodes;
//in __construct()
$this->accountPurchaseNodes = new \Doctrine\Common\Collections\ArrayCollection();
这个没有
//==Purchase =====================================
/**
* @param \Doctrine\Common\Collections\Collection $property
* @OneToMany(targetEntity="PurchaseOrderNode", mappedBy="purchases", cascade={"persist", "remove"});
*/
private $purchaseOrderNodes;
//in __construct()
$this->purchaseOrderNodes = new \Doctrine\Common\Collections\ArrayCollection();
//==PurchaseOrderNode =====================================
/**
*
* @ManyToOne(targetEntity="Purchase", cascade={"all"}, fetch="EAGER")
* @JoinColumn(name="purchaseRefId", referencedColumnName="refId")
*
**/
private $purchase;
/**
*
* @ManyToOne(targetEntity="Order", cascade={"all"}, fetch="EAGER")
* @JoinColumn(name="orderRefId", referencedColumnName="refId")
*
**/
private $order;
//==Order =====================================
/**
* @param \Doctrine\Common\Collections\Collection $property
* @OneToMany(targetEntity="PurchaseOrderNode", mappedBy="order", cascade={"persist", "remove"});
*/
private $purchaseOrderNodes;
//in __construct()
$this->purchaseOrderNodes = new \Doctrine\Common\Collections\ArrayCollection();