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
));
You should declare your QueryBuilder in your Repository such as (createQueryBuilder accepts argument) :
public function findOrdersByDate()
{
$qb = $this->createQueryBuilder('o')
->orderBy('o.date', 'asc');
return $qb
->getQuery()
->getResult();
}
In your controller :
$orderResult = $this->getDoctrine()->getRepository("AppBundle:Order")->findOrdersByDate();
EDIT : As Imanali Mamadiev has pointed out : replace "order" by just "o" to avoid SQL Keywords conflicts
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With