Reputation: 356
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?
Upvotes: 1
Views: 563
Reputation: 1529
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
Upvotes: 2