@@ -514,6 +514,186 @@ mod many_relation {
514
514
Ok ( ( ) )
515
515
}
516
516
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
+
517
697
fn schema_23742 ( ) -> String {
518
698
let schema = indoc ! {
519
699
r#"model Top {
@@ -522,7 +702,7 @@ mod many_relation {
522
702
middleId Int?
523
703
middle Middle? @relation(fields: [middleId], references: [id])
524
704
525
- #m2m(bottoms, Bottom[], id, Int)
705
+ #m2m(bottoms, Bottom[], id, Int)
526
706
}
527
707
528
708
model Middle {
@@ -579,6 +759,71 @@ mod many_relation {
579
759
Ok ( ( ) )
580
760
}
581
761
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
+
582
827
async fn test_data ( runner : & Runner ) -> TestResult < ( ) > {
583
828
runner
584
829
. query ( indoc ! { r#"
0 commit comments