8000 `Query::getResult` and `Query::toIterable` results differ when selecting multiple entities. by ajgarlag · Pull Request #9106 · doctrine/orm · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Query::getResult and Query::toIterable results differ when selecting multiple entities. #9106

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

Conversation

ajgarlag
Copy link
Contributor
@ajgarlag ajgarlag commented Oct 7, 2021

While working on #9098 I've found this bug so I open this PR with a test for the exposed bug.

For the test in the PR with 4 articles (a), for 1 author (u), Query::getResult returns 5 results because it only returns one entity per position, while Query::toIterable returns 4 results because it combines the selected entities.

  • Query::getResult output is [a1, u, a2, a3, a4]
  • Query::toIterable output is [[a1, u], [a2, u], [a3, u], [a4, u]]

I prefer the Query::toIterable output, so my questions are:

  • must we fix Query::toIterable to mimic the Query::getResult output?
  • if we fix it, must we add another iterable funcion to Query with the same output currently produced by Query::toIterable?
  • can we assume that output from Query::toIterable and Query::getResult can differ when selecting multiple entities?

@ajgarlag ajgarlag force-pushed the bugfix-iterable-with-multiple-entities branch from d1f6331 to 8188907 Compare October 8, 2021 11:21
@bhushan
Copy link
Contributor
bhushan commented Oct 16, 2021

@greg0ire ‘Query::toIterable’ and ‘Query::getResult’ are they expected to have different outputs? Seems like yes .. but if No then it seems valid problem!!!

@greg0ire
Copy link
Member

I don't know, but I've found this note in the docs:

Iterating results is not possible with queries that fetch-join a collection-valued association. The nature of such SQL result sets is not suitable for incremental hydration.

https://www.doctrine-project.org/projects/doctrine-orm/en/2.10/reference/batch-processing.html

This use case does not seem to be supported at all. Maybe we should throw in that sort of case.
The DQL query does not make a lot of sense to me either: I'd use 'select a, a.user from ' . CmsArticle::class'

@bhushan
Copy link
Contributor
bhushan commented Oct 16, 2021

@ajgarlag hi, by checking docs, Query::toIterable can be used for bulk operations and Query::getResult is for getting hydrated data..

Also Query::toIterable doesn't support joins ..

IMHO functionality is working as expected for both functions.

@bhushan
Copy link
Contributor
bhushan commented Oct 16, 2021

May be you can PR something which throws exceptions when such case occurs !! @ajgarlag

cc @greg0ire

@greg0ire
Copy link
Member

I think it might make sense. It would be a BC-break, and for that reason the PR should target 3.0.x.
A PR deprecating this could be done against 2.11.x

@ajgarlag
Copy link
Contributor Author

Also Query::toIterable doesn't support joins ..

Query::toIterable does not support fetch-join from a ...toMany associated entity.

There is an exception that is already thrown when the DQL expression includes a fetch-join using a mapped ...toMany association without adding the DISTINCT hint.

if ($this->query->getHint(Query::HINT_INTERNAL_ITERATION) === true && (! $this->query->getHint(self::HINT_DISTINCT) || isset($this->selectedClasses[$joinedDqlAlias]))) {
if ($relation['type'] === ClassMetadata::ONE_TO_MANY || $relation['type'] === ClassMetadata::MANY_TO_MANY) {
throw QueryException::iterateWithFetchJoinNotAllowed($assoc);
}
}

The problem exposed it the tests occur when selecting multiple entities with an arbitrary JOIN, or even without any JOIN. I'll update the test case to select completely unrelated entities.

@ajgarlag ajgarlag force-pushed the 8000 bugfix-iterable-with-multiple-entities branch from 8188907 to 164b087 Compare October 18, 2021 12:18
@ajgarlag ajgarlag force-pushed the bugfix-iterable-with-multiple-entities branch from 164b087 to f982b92 Compare October 18, 2021 12:44
@derrabus derrabus changed the base branch from 2.10.x to 2.12.x April 24, 2022 19:55
Copy link
Contributor

There hasn't been any activity on this pull request in the past 90 days, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 7 days.
If you want to continue working on it, please leave a comment.

@github-actions github-actions bot added the Stale label Nov 28, 2024
Copy link
Contributor
github-actions bot commented Dec 5, 2024

This pull request was closed due to inactivity.

@github-actions github-actions bot closed this Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0