0
我有以下的库:意想不到的结果
$qb = $this->getEntityManager()->createQueryBuilder();
$qb
->select('r')
->from('MyBundle:Rating', 'r')
->groupBy('r.year');
$result = $qb->getQuery()->execute();
return $result;
控制器做一个转储:
array(2) {
[0]=>
object(My\Entity\Rating)#553 (5) {
["id":protected]=>
int(2)
["index":protected]=>
int(1)
["year":protected]=>
int(2010)
["percentage":protected]=>
float(2.5)
}
[1]=>
object(My\Entity\Rating)#550 (5) {
["id":protected]=>
int(1)
["index":protected]=>
int(1)
["year":protected]=>
int(2016)
["percentage":protected]=>
float(0)
}
}
- 我期待随着年龄的增长为指标的数组,与值是与年份相匹配的对象数组,如果不是这样的话?
- db中有大约10条记录。一些如何只有这2出现。只输入两个不同年份的记录,这可能是只有两个记录的原因。有人知道为什么吗?
我该如何达到1的预期?
感谢您的关注,但它并没有让我接近。通过删除groupBy,本练习的目标将被省略。另外,为了更加正确,默认情况下,Doctrine用对象给出了一个ArrayCollection。 – apfz