diff --git a/libs/datamodel/core/src/transform/ast_to_dml/validate.rs b/libs/datamodel/core/src/transform/ast_to_dml/validate.rs index dc8fb996f04b..26cc9d677a6f 100644 --- a/libs/datamodel/core/src/transform/ast_to_dml/validate.rs +++ b/libs/datamodel/core/src/transform/ast_to_dml/validate.rs @@ -416,7 +416,7 @@ impl<'a> Validator<'a> { // skip many-to-many if field.is_list() && related_field.is_list() { - return; + continue; } // we skipped many-to-many relations, so one of the sides either has diff --git a/libs/datamodel/core/tests/attributes/relations/referential_actions.rs b/libs/datamodel/core/tests/attributes/relations/referential_actions.rs index 4dade506e57f..dbcb6fe56438 100644 --- a/libs/datamodel/core/tests/attributes/relations/referential_actions.rs +++ b/libs/datamodel/core/tests/attributes/relations/referential_actions.rs @@ -803,59 +803,66 @@ fn sql_server_cascading_cyclic_hop_over_table_relations() { fn sql_server_cascading_cyclic_hop_over_backrelation() { let dml = indoc! { r#" - datasource db { + datasource test { provider = "sqlserver" - url = "sqlserver://" + url = "sqlserver://localhost:1433;database=master;user=SA;password=;trustServerCertificate=true" } generator client { - provider = "prisma-client-js" - previewFeatures = ["referentialActions", "microsoftSqlServer"] + provider = "prisma-client-js" + previewFeatures = ["microsoftSqlServer", "referentialActions"] } - model A { - id Int @id @default(autoincrement()) - bId Int - b B @relation(fields: [bId], references: [id]) - cs C[] + model User { + id Int @id @default(autoincrement()) + comments Comment[] + posts Post[] } - model B { - id Int @id @default(autoincrement()) - as A[] - cs C[] + model Post { + id Int @id @default(autoincrement()) + authorId Int + author User @relation(fields: [authorId], references: [id]) + comments Comment[] + tags Tag[] @relation("TagToPost") } - model C { - id Int @id @default(autoincrement()) - aId Int - bId Int - a A @relation(fields: [aId], references: [id]) - b B @relation(fields: [bId], references: [id]) + model Comment { + id Int @id @default(autoincrement()) + writtenById Int + postId Int + writtenBy User @relation(fields: [writtenById], references: [id]) + post Post @relation(fields: [postId], references: [id]) + } + + model Tag { + id Int @id @default(autoincrement()) + tag String @unique + posts Post[] @relation("TagToPost") } "#}; let expect = expect![[r#" error: Error parsing attribute "@relation": Reference causes a cycle or multiple cascade paths. One of the @relation attributes in this cycle must have `onDelete` and `onUpdate` referential actions set to `NoAction`. Implicit default `onUpdate` value: `Cascade`. - --> schema.prisma:14 + --> schema.prisma:20  |  - 13 |  bId Int - 14 |  b B @relation(fields: [bId], references: [id]) - 15 |  cs C[] + 19 |  authorId Int + 20 |  author User @relation(fields: [authorId], references: [id]) + 21 |  comments Comment[]  |  error: Error parsing attribute "@relation": Reference causes a cycle or multiple cascade paths. One of the @relation attributes in this cycle must have `onDelete` and `onUpdate` referential actions set to `NoAction`. Implicit default `onUpdate` value: `Cascade`. - --> schema.prisma:28 + --> schema.prisma:29  |  - 27 |  bId Int - 28 |  a A @relation(fields: [aId], references: [id]) - 29 |  b B @relation(fields: [bId], references: [id]) + 28 |  postId Int + 29 |  writtenBy User @relation(fields: [writtenById], references: [id]) + 30 |  post Post @relation(fields: [postId], references: [id])  |  error: Error parsing attribute "@relation": Reference causes a cycle or multiple cascade paths. One of the @relation attributes in this cycle must have `onDelete` and `onUpdate` referential actions set to `NoAction`. Implicit default `onUpdate` value: `Cascade`. - --> schema.prisma:29 + --> schema.prisma:30  |  - 28 |  a A @relation(fields: [aId], references: [id]) - 29 |  b B @relation(fields: [bId], references: [id]) - 30 | } + 29 |  writtenBy User @relation(fields: [writtenById], references: [id]) + 30 |  post Post @relation(fields: [postId], references: [id]) + 31 | }  |  "#]];