问题描述:

I try to do a SELECT d.user AS user type of query. But this part is not allowed in Doctrine it seems.

I try to get a nice array as follows:

array(

'week' => 39

'year' => 2016

'user' => UserObject{}

I have the following DQL:

$qb = $this->createQueryBuilder('d')

->select("d.user AS user, WEEK(d.date, 3) AS week, DATE_FORMAT(d.date, '%x') AS year")

->join('d.user', 'u')

->orderBy('d.date', 'ASC')

->getQuery();

return $qb->getResult();

Of course, I can do a select("d, etc however I want to directly have the user as a key in the returning array.

The error I get with the above code is:

[Semantical Error] line 0, col 9 near 'user AS user,': Error: Invalid PathExpression. Must be a StateFieldPathExpression.

I have already added the join, but that seems not to help.

网友答案:

I'm not sure it will give you exactly the result you want (maybe you will have to try the Doctrine\ORM\Query::HYDRATE_ARRAY hydrator), but can something like that do the trick?

$qb = $this->createQueryBuilder('d')
            ->select("user, WEEK(d.date, 3) AS week, DATE_FORMAT(d.date, '%x') AS year")
            ->leftJoin('d.user', 'user')
            ->orderBy('d.date', 'ASC')
            ->getQuery();

return $qb->getResult();
相关阅读:
Top