Search code examples
phpsymfonydoctrine-ormquery-builderdql

order date query, syntax error


The following query I want to use to order the dates of order placed by stores. I want to do them in ascending order however when I try to test run this I get the following error:

[Syntax Error] line 0, col 7: Error: Expected IdentificationVariable | ScalarExpression | AggregateExpression | FunctionDeclaration | PartialObjectExpression | "(" Subselect ")" | CaseExpression, got 'order'

$orderSales = $this->getDoctrine()->getRepository("AppBundle:Order")->createQueryBuilder('order');

    $orderSales->orderBy('order.date', 'asc');
    $orderSales = $orderSales->getQuery();
    $orderResult = $orderSales->getResult();

I do render orderResult in the .twig template

return $this->render('admin/store/sales/adminsales.html.twig', array(
                            'orderResult' =>$orderResult
    ));

Solution

  • Error when using word order in createQueryBuilder('order')

    Change order

    To

    just o for example createQueryBuilder('o')

    Result:

    $orderSales = $this->getDoctrine()->getRepository("AppBundle:Order")->createQueryBuilder('o');
    
    $orderSales->orderBy('o.date', 'asc');
    $orderSales = $orderSales->getQuery();
    $orderResult = $orderSales->getResult();