DDC-2133: Issue with Query::iterate and query mixed results #2684

Closed
opened 2026-01-22 14:00:26 +01:00 by admin · 5 comments
Owner

Originally created by @doctrinebot on GitHub (Nov 9, 2012).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user deatheriam:

Consider this code:

$dql = "
    SELECT Page, Product.name
    FROM Dlayer\\Entity\\Page Page
    INNER JOIN Page.Product Product
    ";
$q = ($em->createQuery($dql));
foreach ($q->iterate() as $entry) {
  $page = $entry[0][0];
  $name = $entry[0]['name'];
}

This results with undefined index: 'name' for the second entry.

First result keys are (notice just one array element with index 0):

0
array(2) {
  [0] =>
  int(0)
  [1] =>
  string(4) "name"
} 

but all others are different (notice two array elements with index 0 and the other one that is incrementing):

the second one:
0
array(1) {
  [0] =>
  int(0)
}
1
array(1) {
  [0] =>
  string(4) "name"
} 
the third one:
0
array(1) {
  [0] =>
  int(0)
}
2
array(1) {
  [0] =>
  string(4) "name"
} 

What's wrong with this approach? Is it a bug or mixed results should not be used with the iterate method?

Originally created by @doctrinebot on GitHub (Nov 9, 2012). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user deatheriam: Consider this code: ``` $dql = " SELECT Page, Product.name FROM Dlayer\\Entity\\Page Page INNER JOIN Page.Product Product "; $q = ($em->createQuery($dql)); foreach ($q->iterate() as $entry) { $page = $entry[0][0]; $name = $entry[0]['name']; } ``` This results with undefined index: 'name' for the second entry. First result keys are (notice just one array element with index 0): ``` 0 array(2) { [0] => int(0) [1] => string(4) "name" } ``` but all others are different (notice two array elements with index 0 and the other one that is incrementing): ``` the second one: 0 array(1) { [0] => int(0) } 1 array(1) { [0] => string(4) "name" } the third one: 0 array(1) { [0] => int(0) } 2 array(1) { [0] => string(4) "name" } ``` What's wrong with this approach? Is it a bug or mixed results should not be used with the iterate method?
admin added the Bug label 2026-01-22 14:00:26 +01:00
admin closed this issue 2026-01-22 14:00:26 +01:00
Author
Owner

@doctrinebot commented on GitHub (Nov 9, 2012):

@doctrinebot commented on GitHub (Nov 9, 2012): - is duplicated by [DDC-1314: DQL permits partial select using SQL](http://www.doctrine-project.org/jira/browse/DDC-1314)
Author
Owner

@doctrinebot commented on GitHub (Nov 12, 2012):

Comment created by @beberlei:

This is a known issue that we don't have found a BC fix for and as I understand [~guilhermeblanco] requires considerable refactoring.

@doctrinebot commented on GitHub (Nov 12, 2012): Comment created by @beberlei: This is a known issue that we don't have found a BC fix for and as I understand [~guilhermeblanco] requires considerable refactoring.
Author
Owner

@aistis- commented on GitHub (Jul 10, 2017):

I confirm the same issue persists in v2.5.6

Workaround :D

private function fixMalformedResult(array $row): array
{
    if (1 < count($row)) {
        return [array_merge(...$row)];
    }

    return $row;
}
@aistis- commented on GitHub (Jul 10, 2017): I confirm the same issue persists in v2.5.6 Workaround :D ```php private function fixMalformedResult(array $row): array { if (1 < count($row)) { return [array_merge(...$row)]; } return $row; } ```
Author
Owner

@kbond commented on GitHub (Dec 5, 2020):

It appears this has been solved in 2.8 with the addition of AbstractQuery::toIterable() (#7885, #8268 & #8293)

@kbond commented on GitHub (Dec 5, 2020): It appears this has been solved in 2.8 with the addition of `AbstractQuery::toIterable()` (#7885, #8268 & #8293)
Author
Owner

@beberlei commented on GitHub (Dec 5, 2020):

@kbond perfect :) closing

@beberlei commented on GitHub (Dec 5, 2020): @kbond perfect :) closing
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#2684