Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with toIterable() and selecting multiple entities #8413

Closed
Cartman34 opened this issue Jan 6, 2021 · 2 comments · Fixed by #8467
Closed

Issue with toIterable() and selecting multiple entities #8413

Cartman34 opened this issue Jan 6, 2021 · 2 comments · Fixed by #8467
Milestone

Comments

@Cartman34
Copy link

My code was previously working and since the last update, all the application is down due to toIterable() returning only the last entity when selecting multiple entities.

At line 179 in AbstractHydrator, Doctrine is doing yield end($result); causing the issue, the call to end() function should not be used.
$result is a simple array containing all retrieved entities, calling end() is just returning the last one.

I tested and the solution is really simple: Just remove the end() call, only yield $result;

This may be related to #8410

Cartman34 pushed a commit to Cartman34/orm that referenced this issue Jan 6, 2021
Fix doctrine#8413
Now allowing to select multiple entities and return all of them
@SenseException
Copy link
Member

Can you please show your code example and add the current result as also your expected result?

@Cartman34
Copy link
Author

Ok, so this is a summary version of my code:

$userItems = $queryBuilder
	->select('event', 'event_user')
	->leftJoin(EventUser::class, 'event_user', Join::WITH, 'event = event_user.event AND event_user.user = :user')
	->getQuery()->toIterable();
foreach($userItems as $userItem) {
	// Got: No $userItem[1], $userItem[0] contains event_user
	// Expected : $userItem[0] contain event and $userItem[1] event_user
}

beberlei added a commit to beberlei/doctrine2 that referenced this issue Feb 8, 2021
When multiple entity results are part of a row, the result handling
must be different. In addition mixed results with scalars are broken
and now throw an exception as illegal operation.
beberlei added a commit to beberlei/doctrine2 that referenced this issue Feb 8, 2021
@beberlei beberlei added this to the 2.8.2 milestone Feb 8, 2021
beberlei added a commit to beberlei/doctrine2 that referenced this issue Feb 16, 2021
When multiple entity results are part of a row, the result handling
must be different. In addition mixed results with scalars are broken
and now throw an exception as illegal operation.
beberlei added a commit to beberlei/doctrine2 that referenced this issue Feb 16, 2021
beberlei added a commit that referenced this issue Feb 16, 2021
* [GH-8410] Fix memory leak in new toIterable and state bug.

The new AbstractQuery::toIterable() had a memory leak that
AbstractQuery::iterable() did not have. This leak is now fixed.

After fixing the leak, one test failed where the identity map in
ObjectHydrator triggered and lead to a notice. Introduced a new
AbstractHydrator::cleanupAfterRowIteration() that the ObjectHydrator
uses to cleanup the state.

* [GH-8413] Bugfix: Iterating with multiple, mixed results

When multiple entity results are part of a row, the result handling
must be different. In addition mixed results with scalars are broken
and now throw an exception as illegal operation.

* Housekeeping: phpcs

* [GH-8413] Add assertions for entity alias iteration.

* [GH-8387] Missing @deprecated on Query::iterate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants