Skip to content

Commit

Permalink
fix: nested some filters should work (#4968)
Browse files Browse the repository at this point in the history
  • Loading branch information
Weakky authored Aug 12, 2024
1 parent e1242e1 commit 98ab935
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,71 @@ mod many_relation {
Ok(())
}

fn schema_23742() -> String {
let schema = indoc! {
r#"model Top {
#id(id, Int, @id)
middleId Int?
middle Middle? @relation(fields: [middleId], references: [id])
#m2m(bottoms, Bottom[], id, Int)
}
model Middle {
#id(id, Int, @id)
bottoms Bottom[]
tops Top[]
}
model Bottom {
#id(id, Int, @id)
middleId Int?
middle Middle? @relation(fields: [middleId], references: [id])
#m2m(tops, Top[], id, Int)
}"#
};

schema.to_owned()
}

// Regression test for https://github.com/prisma/prisma/issues/23742
// SQL Server excluded because the m2m fragment does not support onUpdate/onDelete args which are needed.
#[connector_test(schema(schema_23742), exclude(SqlServer))]
async fn prisma_23742(runner: Runner) -> TestResult<()> {
run_query!(
&runner,
r#"mutation {
createOneTop(data: {
id: 1,
middle: { create: { id: 1, bottoms: { create: { id: 1, tops: { create: { id: 2 } } } } } }
}) {
id
}}"#
);

insta::assert_snapshot!(
run_query!(&runner, r#"{
findUniqueTop(where: { id: 1 }) {
middle {
bottoms(
where: { tops: { some: { id: 2 } } }
) {
id
}
}
}
}
"#),
@r###"{"data":{"findUniqueTop":{"middle":{"bottoms":[{"id":1}]}}}}"###
);

Ok(())
}

async fn test_data(runner: &Runner) -> TestResult<()> {
runner
.query(indoc! { r#"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,10 @@ fn extract_filter_scalars(f: &Filter) -> Vec<ScalarFieldRef> {
Filter::Scalar(x) => x.scalar_fields().into_iter().map(ToOwned::to_owned).collect(),
Filter::ScalarList(x) => vec![x.field.clone()],
Filter::OneRelationIsNull(x) => join_fields(&x.field),
Filter::Relation(x) => join_fields(&x.field),
Filter::Relation(x) => vec![join_fields(&x.field), extract_filter_scalars(&x.nested_filter)]
.into_iter()
.flatten()
.collect(),
_ => Vec::new(),
}
}
Expand Down

0 comments on commit 98ab935

Please sign in to comment.