Reputation: 9269
So, i have this query in my repository :
$qb = $this->_em->createQueryBuilder();
$qb->select(array('a', 'COUNT(t.id) as counter'))
->from('MyProjectBundle:Account', 'a')
->leftjoin('a.tha', 'th')
->leftjoin('th.the', 't')
->where('t.is_good = ?1')
->groupby('a')
->orderby('counter', 'DESC')
->setMaxResults(30)
->setParameters(array(1 => $is_good));
return $qb->getQuery()->getResult();
So, with this query, i have a list of account, order by counter
. When i return the result of this query in json, i can see :
{
"myjson": [
{
"0": {
"username": "blabla",
},
"counter": "2"
}
{
"0": {
"username": "aeiouy",
},
"counter": "1"
}
]
}
You can see the "0"
for each element in my json.. How can i remove these 0 ? I want something like :
{
"myjson": [
{
"username": "blabla",
"counter": "2"
},
{
"username": "aeiouy",
"counter": "1"
}
]
}
Any ideas ?
Upvotes: 0
Views: 641
Reputation: 4304
Try to change it to
$qb = $this->_em->createQueryBuilder();
$qb->select(array('a.username', 'COUNT(t.id) as counter'))
->from('MyProjectBundle:Account', 'a')
->leftjoin('a.tha', 'th')
->leftjoin('th.the', 't')
->where('t.is_good = ?1')
->groupby('a')
->orderby('counter', 'DESC')
->setMaxResults(30)
->setParameters(array(1 => $is_good));
return $qb->getQuery()->getResult();
Upvotes: 1