【发布时间】:2016-01-31 18:05:18
【问题描述】:
您好,我已经使用查询生成器对排名机制进行了简单查询。
$result = $qb
->select('u')
->where('u.status = 1')
->from('PGMainBundle:User', 'u')
->groupBy('u.id')
->addSelect('COUNT(c.id) as HIDDEN nChallenges')
->leftJoin('u.challenges', 'c', 'WITH', 'c.closed = 1' )
->add('orderBy','u.points DESC, nChallenges DESC')
->orderBy('u.points', 'DESC')
->addOrderBy('nChallenges', 'DESC')
->setFirstResult($offset*50)
->setMaxResults(50)
->getQuery()
->getResult();
现在,虽然我的排名机制运行良好,但我想检查一个具有 $id 的用户有什么 loop.index。
这么说,我不想在结果上使用 foreach 循环来这样做。
是否有更优化的方式来返回排名中的“位置”?
可能使用查询生成器?
【问题讨论】:
标签: php symfony query-builder doctrine-query