简体   繁体   English

原则查询:结果创建具有索引偏移量的数组

[英]Doctrine Query: Result creates array with index offset

I have a DQL string: 我有一个DQL字符串:

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. 我想检索一些a,与a有关的c的计数以及最新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子句中列出的多个实体,则水合将返回迭代不同顶级实体的行。” (From http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/dql-doctrine-query-language.html#fetching-multiple-from-entities ) (来自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 最好的祝福

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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