Column Order by causes undefined index

413 Views Asked by At

I have three Entities, which have a relation to each other:

Entity 1:

/** @ORM\OneToMany(targetEntity="ArticleOrderReference", mappedBy="purchaseOrder") */
protected $purchaseOrders;

Entity 2:

/** @ORM\ManyToOne(targetEntity="PurchaseOrder", inversedBy="purchaseOrders") */
protected $purchaseOrder;

 /** @ORM\OneToMany(targetEntity="AOSupplierReference", mappedBy="articleOrderReference") 
 *  @ORM\OrderBy({"supplier" = "ASC"})
 * */
protected $articleOrderReferences;

Entity 3:

/** @ORM\ManyToOne(targetEntity="ArticleOrderReference", inversedBy="articleOrderReferences")
 *  
 */
protected $articleOrderReference;

/** @ORM\ManyToOne(targetEntity="Supplier", inversedBy="suppliers") */
protected $supplier;

My goal is to create a query like this:

$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();

But it displays this error

Notice: Undefined index: supplier in /var/www/symfony/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php line 40 

, since I used the @ORM\OrderBy({"supplier" = "ASC"}) in Entity2. Without this order by it works. I don't know why it throws an Undefined index error. Any ideas how I can fix this?

I know that the variable names are badly chosen.

0

There are 0 best solutions below