简体   繁体   中英

Doctrine Query: Result creates array with index offset

I have a DQL string:

SELECT DISTINCT a,
       b,
       (
           SELECT COUNT(c)
           FROM ..\Entity\EntityC c
           WHERE c.b = b
       ),
       (
           SELECT MAX(c2.date)
           FROM ..\Entity\EntityC c2
           WHERE c2.b = b
       )
 FROM ..\Entity\EntityA a
 JOIN a.b b
 ...

I want to retrieve some a's, the count of c's that relate to ab, and the date of the latest c. My code DOES generate the results I want, but the resulting arrays have an offset in their indices:

array(size = [rows])
  0 => array (size = 3)
         0 => Entity(a)
         1 => int(COUNT(c))
         3 => date(MAX(c2.date))
  1 => array (size = 3)
         0 => Entity(a)
         1 => int(COUNT(c))
         3 => date(MAX(c2.date))
  ...

Why does this offset happen, and is there a way to prevent this?

Maybe it is related to this "If you fetch multiple entities that are listed in the FROM clause then the hydration will return the rows iterating the different top-level entities." (From http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/dql-doctrine-query-language.html#fetching-multiple-from-entities )

$dql = "SELECT u, g FROM User u, Group g";

array
     [0] => Object (User)
     [1] => Object (Group)
     [2] => Object (User)
     [3] => Object (Group)

Could you verify doing a dump on the next row? Best regards

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM