Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Relationship/Referential Actions #15

Closed
1 of 2 tasks
marcjulian opened this issue Jul 13, 2021 · 2 comments · Fixed by #16
Closed
1 of 2 tasks

Add support for Relationship/Referential Actions #15

marcjulian opened this issue Jul 13, 2021 · 2 comments · Fixed by #16

Comments

@marcjulian
Copy link
Member

marcjulian commented Jul 13, 2021

Prisma supports Referential Actions (in Preview) with release 2.26.0. Add those referential actions to the DBML output.

DMMF type

@marcjulian marcjulian linked a pull request Jul 29, 2021 that will close this issue
@marcjulian
Copy link
Member Author

marcjulian commented Jul 29, 2021

Referential action defaults are not available via the DMMF type during the generator step.

For example take the following Prisma Schema with a Mandatory relation between User and Post.

model Post {
  id        Int     @id @default(autoincrement())
  title     String
  author    User    @relation(fields: [authorId], references: [id])
  authorId  Int
}

model User {
  id    Int         @id @default(autoincrement())
  posts Post[]
}

The referential action is not explicitly definied in the schema and results in the default Restrict, the generated migration correctly sets ON DELETE RESTRICT for this relation ship.

During the generator step Field.relationOnDelete is undefined, but expected to be Restrict.

Same happens for an Optional relation

model Post {
  id        Int     @id @default(autoincrement())
  title     String
  author?    User    @relation(fields: [authorId], references: [id])
  authorId?  Int
}

model User {
  id    Int         @id @default(autoincrement())
  posts Post[]
}

The referential default is SetNull, correctly applied in the migration.

During the generator step Field.relationOnDelete is undefined, but expected to be SetNull.


If the default are set explicitly in the schema those values are than also available during the generator step.

model Post {
  id        Int     @id @default(autoincrement())
  title     String
  author    User    @relation(fields: [authorId], references: [id], onDelete: Restrict)
  authorId  Int
}

model User {
  id    Int         @id @default(autoincrement())
  posts Post[]
}

During the generator step Field.relationOnDelete is Restrict, but expected to be Restrict.

model Post {
  id        Int     @id @default(autoincrement())
  title     String
  author?    User    @relation(fields: [authorId], references: [id], onDelete: SetNull)
  authorId?  Int
}

model User {
  id    Int         @id @default(autoincrement())
  posts Post[]
}

During the generator step Field.relationOnDelete is SetNull, but expected to be SetNull.

@marcjulian
Copy link
Member Author

Referential defaults for onDelete are correct with prisma@3.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant