学说查询:结果创建具有索引偏移的数组



我有一个dql字符串:

SELECT DISTINCT a,
       b,
       (
           SELECT COUNT(c)
           FROM ..EntityEntityC c
           WHERE c.b = b
       ),
       (
           SELECT MAX(c2.date)
           FROM ..EntityEntityC c2
           WHERE c2.b = b
       )
 FROM ..EntityEntityA a
 JOIN a.b b
 ...

我想检索一些A的A,与A.B相关的C数以及最新C的日期。我的代码确实会生成我想要的结果,但是结果阵列的索引有偏移:

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))
  ...

为什么会发生这种偏移,有没有办法防止这种情况?

也许与此相关"如果您获取从子句中列出的多个实体,那么水合将返回迭代不同顶级实体的行。"(来自http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/dql-doctrine-query-language.html#fetching-multiph-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)

您可以验证在下一行上进行转储吗?最好的问候

相关内容

  • 没有找到相关文章

最新更新