Symfony2 Doctrine选择具有虚拟值的虚拟列

时间:2014-08-15 06:29:43

标签: php symfony doctrine-orm doctrine

我需要:

select *, 0 as count from abc; 

在doctrine查询构建器中。我正在使用Symfony2

$qb = $this->getEntityManager()->createQueryBuilder();
$r = $qb->select('s, 0 as count')
        ->from('Wenweipo\SmileysBundle\Entity\Smileys', 's')
        ->innerJoin('s.group', 'g')
        ->where('g.id = :group_id')
        ->setParameter('group_id', $group_id)
        ->getQuery()
        ->execute(); 

但上述查询不起作用。

1 个答案:

答案 0 :(得分:1)

正如@meze评论我更新了字段名称并且工作正常。

$r = $qb->select('s,0 as aaaa')
                ->from('Wenweipo\SmileysBundle\Entity\Smileys', 's')
                ->innerJoin('s.group', 'g')
                ->where('g.id = :group_id')
                ->setParameter('group_id', $group_id)
                ->getQuery()
                ->getResult();