0

I have a query in a repository like :

        $qb->select('f.state as link')
            ->from('MyProjectBundle:Friend', 'f')
            ->where('CONDITIONS');
        return $qb->getQuery()->getResult();

So, this query return the state with you and a friend. In my controller i return :

return array('link' => $state);

$state is the result of my query. I can only have one result with this query, it's just the state with ONE other user. So, when i check the response, i have (in json) :

    {
    "link": [
        {
            "link": 1
        }
    ]    
   }

How can i remove the array [] in this json ? It's useless here.. Thanks !

2
  • return array(current($state)); ? Commented Jul 30, 2014 at 9:19
  • Nice ! Answer my question if you want ;) Commented Jul 30, 2014 at 9:25

2 Answers 2

1

As expected ;)
You can use return array(current($state));

Sign up to request clarification or add additional context in comments.

Comments

1

You can use getSingleScalarResult() method as explained here :

http://docs.doctrine-project.org/en/2.1/reference/dql-doctrine-query-language.html#query-result-formats

$qb->select('f.state as link')
    ->from('MyProjectBundle:Friend', 'f')
    ->where('CONDITIONS');

return $qb->getQuery()->getSingleScalarResult();

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.