-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
qe: fix mismatch between selection indexes for joins (#4705)
Both the old query builder and the new query builder append virtual selections after all other selections in the query. This means we have to take it into account instead of relying on the fields in the result set to be in the same order as in `FieldSelection`. The old code path converted the selection into virtuals-last form but the new one didn't, which resulted in the cached indexes for the relations and virtuals to be mixed up when selecting relation aggregations before the relations in the query. Now the new code path does the same transformation. Fixes: prisma/team-orm#927
- Loading branch information
Showing
4 changed files
with
99 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,3 +30,4 @@ mod prisma_7072; | |
mod prisma_7434; | ||
mod prisma_8265; | ||
mod prisma_engines_4286; | ||
mod team_orm_927; |
90 changes: 90 additions & 0 deletions
90
query-engine/connector-test-kit-rs/query-engine-tests/tests/new/regressions/team_orm_927.rs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
//! Regression test for https://github.com/prisma/team-orm/issues/927 | ||
use query_engine_tests::*; | ||
|
||
#[test_suite(schema(schema))] | ||
mod count_before_relation { | ||
fn schema() -> String { | ||
indoc! { | ||
r#" | ||
model Parent { | ||
#id(id, Int, @id) | ||
children Child[] | ||
} | ||
model Child { | ||
#id(id, Int, @id) | ||
parentId Int | ||
parent Parent @relation(fields: [parentId], references: [id]) | ||
} | ||
"# | ||
} | ||
.to_owned() | ||
} | ||
|
||
#[connector_test] | ||
async fn find_unique(runner: Runner) -> TestResult<()> { | ||
seed(&runner).await?; | ||
|
||
insta::assert_snapshot!( | ||
run_query!( | ||
runner, | ||
r#" | ||
query { | ||
findUniqueParent( | ||
where: { id: 1 } | ||
) { | ||
_count { children } | ||
children { id } | ||
} | ||
} | ||
"# | ||
), | ||
@r###"{"data":{"findUniqueParent":{"_count":{"children":1},"children":[{"id":1}]}}}"### | ||
); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[connector_test] | ||
async fn find_many(runner: Runner) -> TestResult<()> { | ||
seed(&runner).await?; | ||
|
||
insta::assert_snapshot!( | ||
run_query!( | ||
runner, | ||
r#" | ||
query { | ||
findManyParent { | ||
_count { children } | ||
children { id } | ||
} | ||
} | ||
"# | ||
), | ||
@r###"{"data":{"findManyParent":[{"_count":{"children":1},"children":[{"id":1}]}]}}"### | ||
); | ||
|
||
Ok(()) | ||
} | ||
|
||
async fn seed(runner: &Runner) -> TestResult<()> { | ||
run_query!( | ||
runner, | ||
r#" | ||
mutation { | ||
createOneParent( | ||
data: { | ||
id: 1, | ||
children: { | ||
create: { id: 1 } | ||
} | ||
} | ||
) { id } | ||
} | ||
"# | ||
); | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains 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
This file contains 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