fix(query-builder): skip eager relation query when the main query already joins it - #12777
Open
michaelbromley wants to merge 1 commit into
Open
fix(query-builder): skip eager relation query when the main query already joins it#12777michaelbromley wants to merge 1 commit into
michaelbromley wants to merge 1 commit into
Conversation
commit: |
Code Review by Qodo
1. Ignores loadEagerRelations flag
|
|
alumni
approved these changes
Aug 26, 2026
gioboa
approved these changes
Aug 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #12775
Under
relationLoadStrategy: 'query', every eager relation of the queried entity was fetched by a separate query after the main one, even when the main query had already joined and selected that relation. The relation was therefore read twice, and any column transformer on it ran twice per row.Since the query strategy no longer joins eager relations into the main query, this is easy to hit: an
ORDER BYor aWHEREon a column of an eager relation forces you to create the join yourself, and creating it was enough to cause the second fetch.The separate load is now skipped when the main query already hydrates the relation exactly as that load would. A join only qualifies when all of the following hold:
LEFTjoin of the relation off the main alias, selected in full, and not mapped onto another property withleftJoinAndMapMany/leftJoinAndMapOneONcondition, and noWHEREorHAVINGclause names the joined alias, since either of those hydrates only a subset of the relationselect,orderorrelations, none of which a plain join reproducesAnything outside those conditions keeps loading the relation by its own query, so what callers get back is unchanged.
Tests are added to
test/functional/relations/load-strategy/query: one asserting a single query against the relation's table when the join covers it, and three asserting the relation is still loaded in full when anONcondition, aWHEREon the joined alias, or the related entity's own eager relations mean the join cannot stand in for it.