我有三个实体,它们彼此有关系:
实体 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
,因为我@ORM\OrderBy({"supplier" = "ASC"})
在Entity2中使用了。如果没有这个命令,它就可以工作。我不知道为什么它会引发未定义的索引错误。有什么想法可以解决这个问题吗?
我知道变量名选择不当。