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

Diagnostics: detecting @unique constraint on foreign-key in one-to-many relationships #1355

Open
S4d3ngineer opened this issue Jan 12, 2023 · 0 comments
Labels
domain/schema Issue in the "Schema" domain: Prisma Schema, Introspection, Migrations etc. kind/improvement An improvement to existing feature and code. topic: diagnostics topic: relation topic: validation

Comments

@S4d3ngineer
Copy link

Suggested solution

Inform user when @unique constraint is used on foreign key.

Additional context

I believe that using @unique key in described scenario is unwanted behavior. In the example below setting @unique field on authorId field makes it impossible for User to have multiple Posts.

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

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

Diagnostic should detect this just as it is detects when @unique is not set on foreign key in one-to-one relationship.

@Jolg42 Jolg42 added process/candidate Candidate for next Milestone. kind/improvement An improvement to existing feature and code. topic: validation domain/schema Issue in the "Schema" domain: Prisma Schema, Introspection, Migrations etc. topic: relation topic: diagnostics labels Jan 16, 2023
@janpio janpio removed the process/candidate Candidate for next Milestone. label Jan 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain/schema Issue in the "Schema" domain: Prisma Schema, Introspection, Migrations etc. kind/improvement An improvement to existing feature and code. topic: diagnostics topic: relation topic: validation
Projects
None yet
Development

No branches or pull requests

3 participants