Doctrine DQL查询重写到Query Builder

时间:2014-08-07 08:58:29

标签: doctrine-orm

我有查询

$Select = 'SELECT COUNT(o.Id) FROM Entities\Order o';

如何为查询构建器重写此查询?

$qb = $this->entityManager->createQueryBuilder();
$qb->select(.....

谢谢

1 个答案:

答案 0 :(得分:0)

您可以在documentation中看到,这是非常直接的。

$qb = $this->entityManager->createQueryBuilder();
$result = $qb->select('COUNT(o.Id)')
    ->from('Entities\Order', 'o')
    ->getQuery()
    ->getResult();

如果您只想使用$result中的号码,可以使用

$qb = $this->entityManager->createQueryBuilder();
$result = $qb->select('COUNT(o.Id)')
    ->from('Entities\Order', 'o')
    ->getQuery()
    ->getSingleScalarResult();