Specify table name using namespace in createQuery in Doctrine

Asked

Viewed 41 times

0

I need to create a database query in a table whose name is order and that cannot be changed. I made the following query:

$query = $entityManager->createQuery("SELECT sum(o.orderPrice) 
                                            FROM  \App\Entity\Order  o 
                                            WHERE o.orderEventId = ?1
                                                  o.orderDate <= ?2
                                                  o.orderDate >= ?3")
                            ->setParameters(array(
                                                    1 => $event,
                                                    2 => ' LAST_DAY(CURDATE()) ',
                                                    3 => ' DATE_SUB(LAST_DAY(NOW()), INTERVAL DAY(LAST_DAY(NOW()))-1 DAY)'
                                                 )
                                            );


    $dados['qtd_resultado'] = $query->getResult();

The App Entity Order namespace indicated in FROM points to the following Entity in Doctrine:

namespace App\Entity;

use Doctrine ORM Mapping Entity;

/**
 * @Entity
 * @Table(name="order")
 */
class Order
{
}

The problem occurs in FROM because the word ORDER is reserved, so when mounting the query the system presents syntax error. What is the correct way to enter the table name?

  • does so select * from 'order'

  • between single quotes it does not see as command but as text

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.