Skip to content

Commit d7b86af

Browse files
authored
Merge branch 'main' into i24331
2 parents f33c2e4 + f2561ec commit d7b86af

File tree

4 files changed

+255
-17
lines changed

4 files changed

+255
-17
lines changed

.github/workflows/build-engines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
echo "Repository Owner: $${{ github.repository_owner }}"
5454
echo "Pull Request Author: ${{ github.actor }}"
5555
echo "Pull Request Author Association: ${{ github.event.pull_request.author_association }}"
56-
echo "Commit message:${{ steps.commit-msg.outputs.commit-msg }}"
56+
# echo "Commit message:${{ steps.commit-msg.outputs.commit-msg }}"
5757
echo "Commit message contains [integration]: ${{ contains(steps.commit-msg.outputs.commit-msg, '[integration]') }}"
5858
5959
- name: 'Check if commit message conatains `[integration]` and the PR author has permissions to trigger the workflow'

Cargo.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/filters/many_relation.rs

Lines changed: 246 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,186 @@ mod many_relation {
514514
Ok(())
515515
}
516516

517+
fn schema_25103() -> String {
518+
let schema = indoc! {
519+
r#"model Contact {
520+
#id(id, String, @id)
521+
identities Identity[]
522+
}
523+
524+
model Identity {
525+
#id(id, String, @id)
526+
contactId String
527+
contact Contact @relation(fields: [contactId], references: [id])
528+
subscriptions Subscription[]
529+
}
530+
531+
model Subscription {
532+
#id(id, String, @id)
533+
identityId String
534+
audienceId String
535+
optedOutAt DateTime?
536+
audience Audience @relation(fields: [audienceId], references: [id])
537+
identity Identity @relation(fields: [identityId], references: [id])
538+
}
539+
540+
model Audience {
541+
#id(id, String, @id)
542+
deletedAt DateTime?
543+
subscriptions Subscription[]
544+
}"#
545+
};
546+
547+
schema.to_owned()
548+
}
549+
550+
// Regression test for https://github.com/prisma/prisma/issues/25103
551+
// SQL Server excluded because the m2m fragment does not support onUpdate/onDelete args which are needed.
552+
#[connector_test(schema(schema_25103), exclude(SqlServer))]
553+
async fn prisma_25103(runner: Runner) -> TestResult<()> {
554+
// Create some sample audiences
555+
run_query!(
556+
&runner,
557+
r#"mutation {
558+
createOneAudience(data: {
559+
id: "audience1",
560+
deletedAt: null
561+
}) {
562+
id
563+
}}"#
564+
);
565+
run_query!(
566+
&runner,
567+
r#"mutation {
568+
createOneAudience(data: {
569+
id: "audience2",
570+
deletedAt: null
571+
}) {
572+
id
573+
}}"#
574+
);
575+
// Create a contact with identities and subscriptions
576+
insta::assert_snapshot!(
577+
run_query!(
578+
&runner,
579+
r#"mutation {
580+
createOneContact(data: {
581+
id: "contact1",
582+
identities: {
583+
create: [
584+
{
585+
id: "identity1",
586+
subscriptions: {
587+
create: [
588+
{
589+
id: "subscription1",
590+
audienceId: "audience1",
591+
optedOutAt: null
592+
},
593+
{
594+
id: "subscription2",
595+
audienceId: "audience2",
596+
optedOutAt: null
597+
}
598+
]
599+
}
600+
}
601+
]
602+
}
603+
}) {
604+
id,
605+
identities (orderBy: { id: asc }) {
606+
id,
607+
subscriptions (orderBy: { id: asc }) {
608+
id,
609+
audienceId
610+
}
611+
}
612+
}}"#
613+
),
614+
@r###"{"data":{"createOneContact":{"id":"contact1","identities":[{"id":"identity1","subscriptions":[{"id":"subscription1","audienceId":"audience1"},{"id":"subscription2","audienceId":"audience2"}]}]}}}"###
615+
);
616+
// Find contacts that include identities whose subscriptions have `optedOutAt = null` and include audiences with `deletedAt = null``
617+
insta::assert_snapshot!(
618+
run_query!(
619+
&runner,
620+
r#"query {
621+
findManyContact(orderBy: { id: asc }) {
622+
id,
623+
identities(orderBy: { id: asc }) {
624+
id,
625+
subscriptions(orderBy: { id: asc }, where: { optedOutAt: null, audience: { deletedAt: null } }) {
626+
id,
627+
identityId,
628+
audience {
629+
id,
630+
deletedAt
631+
}
632+
}
633+
}
634+
}
635+
}"#
636+
),
637+
@r###"{"data":{"findManyContact":[{"id":"contact1","identities":[{"id":"identity1","subscriptions":[{"id":"subscription1","identityId":"identity1","audience":{"id":"audience1","deletedAt":null}},{"id":"subscription2","identityId":"identity1","audience":{"id":"audience2","deletedAt":null}}]}]}]}}"###
638+
);
639+
640+
Ok(())
641+
}
642+
643+
fn schema_25104() -> String {
644+
let schema = indoc! {
645+
r#"
646+
model A {
647+
#id(id, String, @id)
648+
bs B[]
649+
}
650+
651+
model B {
652+
#id(id, String, @id)
653+
a A @relation(fields: [aId], references: [id])
654+
aId String
655+
656+
cs C[]
657+
}
658+
659+
model C {
660+
#id(id, String, @id)
661+
name String
662+
bs B[]
663+
}
664+
"#
665+
};
666+
667+
schema.to_owned()
668+
}
669+
670+
#[connector_test(schema(schema_25104), exclude(MongoDb))]
671+
async fn prisma_25104(runner: Runner) -> TestResult<()> {
672+
insta::assert_snapshot!(
673+
run_query!(
674+
&runner,
675+
r#"
676+
query {
677+
findManyA {
678+
bs(where: {
679+
cs: {
680+
every: {
681+
name: { equals: "a" }
682+
}
683+
}
684+
}) {
685+
id
686+
}
687+
}
688+
}
689+
"#
690+
),
691+
@r###"{"data":{"findManyA":[]}}"###
692+
);
693+
694+
Ok(())
695+
}
696+
517697
fn schema_23742() -> String {
518698
let schema = indoc! {
519699
r#"model Top {
@@ -522,7 +702,7 @@ mod many_relation {
522702
middleId Int?
523703
middle Middle? @relation(fields: [middleId], references: [id])
524704
525-
#m2m(bottoms, Bottom[], id, Int)
705+
#m2m(bottoms, Bottom[], id, Int)
526706
}
527707
528708
model Middle {
@@ -579,6 +759,71 @@ mod many_relation {
579759
Ok(())
580760
}
581761

762+
fn schema_nested_some_filter_m2m_different_pk() -> String {
763+
let schema = indoc! {
764+
r#"
765+
model Top {
766+
#id(topId, Int, @id)
767+
768+
relatedMiddleId Int?
769+
middle Middle? @relation(fields: [relatedMiddleId], references: [middleId])
770+
771+
#m2m(bottoms, Bottom[], bottomId, Int)
772+
}
773+
774+
model Middle {
775+
#id(middleId, Int, @id)
776+
777+
bottoms Bottom[]
778+
tops Top[]
779+
}
780+
781+
model Bottom {
782+
#id(bottomId, Int, @id)
783+
784+
relatedMiddleId Int?
785+
middle Middle? @relation(fields: [relatedMiddleId], references: [middleId])
786+
787+
#m2m(tops, Top[], topId, Int)
788+
}
789+
"#
790+
};
791+
792+
schema.to_owned()
793+
}
794+
795+
#[connector_test(schema(schema_nested_some_filter_m2m_different_pk), exclude(SqlServer))]
796+
async fn nested_some_filter_m2m_different_pk(runner: Runner) -> TestResult<()> {
797+
run_query!(
798+
&runner,
799+
r#"mutation {
800+
createOneTop(data: {
801+
topId: 1,
802+
middle: { create: { middleId: 1, bottoms: { create: { bottomId: 1, tops: { create: { topId: 2 } } } } } }
803+
}) {
804+
topId
805+
}}"#
806+
);
807+
808+
insta::assert_snapshot!(
809+
run_query!(&runner, r#"{
810+
findUniqueTop(where: { topId: 1 }) {
811+
middle {
812+
bottoms(
813+
where: { tops: { some: { topId: 2 } } }
814+
) {
815+
bottomId
816+
}
817+
}
818+
}
819+
}
820+
"#),
821+
@r###"{"data":{"findUniqueTop":{"middle":{"bottoms":[{"bottomId":1}]}}}}"###
822+
);
823+
824+
Ok(())
825+
}
826+
582827
async fn test_data(runner: &Runner) -> TestResult<()> {
583828
runner
584829
.query(indoc! { r#"

query-engine/connectors/sql-query-connector/src/query_builder/select/mod.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -648,20 +648,13 @@ fn extract_filter_scalars(f: &Filter) -> Vec<ScalarFieldRef> {
648648
Filter::Scalar(x) => x.scalar_fields().into_iter().map(ToOwned::to_owned).collect(),
649649
Filter::ScalarList(x) => vec![x.field.clone()],
650650
Filter::OneRelationIsNull(x) => join_fields(&x.field),
651-
Filter::Relation(x) => vec![join_fields(&x.field), extract_filter_scalars(&x.nested_filter)]
652-
.into_iter()
653-
.flatten()
654-
.collect(),
651+
Filter::Relation(x) => join_fields(&x.field),
655652
_ => Vec::new(),
656653
}
657654
}
658655

659656
fn join_fields(rf: &RelationField) -> Vec<ScalarFieldRef> {
660-
if rf.is_inlined_on_enclosing_model() {
661-
rf.scalar_fields()
662-
} else {
663-
rf.related_field().referenced_fields()
664-
}
657+
rf.linking_fields().as_scalar_fields().unwrap_or_default()
665658
}
666659

667660
fn join_alias_name(rf: &RelationField) -> String {

0 commit comments

Comments
 (0)