我有一对关联。它们是多对多的,我使用显式创建的实体来加入它们,这样我就可以获得有关关系的元数据。虽然它们是相同的,但一个有效,另一个无效。更糟糕的是,上周,它们都起作用了,从那以后我就再也没有碰过它们。在 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();