我有三个实体,它们彼此有关系:
实体1:
/** @ORM\OneToMany(targetEntity="ArticleOrderReference", mappedBy="purchaseOrder") */
protected $purchaseOrders;
实体2:
/** @ORM\ManyToOne(targetEntity="PurchaseOrder", inversedBy="purchaseOrders") */
protected $purchaseOrder;
/** @ORM\OneToMany(targetEntity="AOSupplierReference", mappedBy="articleOrderReference")
* @ORM\OrderBy({"supplier" = "ASC"})
* */
protected $articleOrderReferences;
实体3:
/** @ORM\ManyToOne(targetEntity="ArticleOrderReference", inversedBy="articleOrderReferences")
*
*/
protected $articleOrderReference;
/** @ORM\ManyToOne(targetEntity="Supplier", inversedBy="suppliers") */
protected $supplier;
我的目标是创建一个这样的查询:
$order = $this->getDoctrine()->getManager()->createQuery("
SELECT o, a , s
FROM AcmeAppBundle:PurchaseOrder o
JOIN o.purchaseOrders a
JOIN a.articleOrderReferences s
WHERE o.id = :orderId
AND s.supplier = :supplierId
AND s.amount > 0
")
->setParameter('orderId', $orderId)
->setParameter('supplierId', $supplierId)
->getOneOrNullResult();
但它显示此错误
Notice: Undefined index: supplier in /var/www/symfony/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php line 40
,因为我在Entity2中使用了@ORM\OrderBy({"supplier" = "ASC"})
。没有这个顺序,它的工作原理。我不知道它为什么会抛出未定义的索引错误。我有什么想法可以解决这个问题吗?
我知道变量名称选择错误。