Repository navigation
Keep selections aliased as join columns in withGraphFetched() and relation queries (#111) - #340
Merged
Merged
Conversation
lehni
force-pushed
the
fix/rc-aggregate-alias
branch
from
October 12, 2026 20:03
5ac414a to
01c7b10
Compare
lehni
force-pushed
the
fix/rc-aggregate-alias
branch
from
October 12, 2026 20:59
01c7b10 to
4d760a6
Compare
lehni
force-pushed
the
fix/rc-aggregate-alias
branch
from
October 12, 2026 21:02
4d760a6 to
df9061b
Compare
lehni
force-pushed
the
fix/rc-aggregate-alias
branch
from
October 12, 2026 21:18
df9061b to
0c03b67
Compare
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.
What
withGraphFetched()and relation queries (RelationFindOperation) treat a selection without a column, of an aggregate, raw SQL or a subquery, as selecting the column that its alias names, likemax('ownerId as ownerId'),raw('?? as ??', ['ownerId', 'ownerId'])or a subquery.as('ownerId'). They don't select that join column once more. The rule lives in one helper inSelection.js, used where these queries check for missing join columns.findSelection(),hasSelection()andhasSelectionAs()are unchanged, sowithGraphJoined()keeps its strict id check: an aggregate, raw SQL or subquery selected under the name of an id column, likemax('pets.id as id'), still throws.Why
Aggregates are meant to select only their aliases since #111, and raw SQL and subqueries with an alias select only that alias too, but nothing matched these aliases. For a query like
Pet.query().max('ownerId as ownerId').groupBy('ownerId').withGraphFetched('owner'),withGraphFetched()selectedownerIda second time as an internal selection and then removed it from the result, so the selected value was gone.The alias only counts where objection reads the join columns from the result rows. In
withGraphJoined(), such a selection under an id name would be used as the root model's id, so it stays an error there.Tests
should keep an aggregate aliased as the join column (#111)fails onnext.should keep raw and subquery selections aliased as the join column (#111)fails with only aggregates matched.should throw if the user selects raws, subqueries or aggregates under the names of the idsalso checksmax('pets.id as id').Part of #53.