0

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 ?

1 Answer 1

1

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();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.