1

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 a.b, 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?

1 Answer 1

2

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

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

1 Comment

I already assumed that the problem lies within hydration, but your suggestion goes another way than my problem. I will edit my question for details.

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.