question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

1 to 1 relations get @unique applied.

See original GitHub issue

I am having an issue with Prisma 1 to 1 relationships, prisma formats my relation with @unique which creates a unique constraint on the column. This makes it to where the field can only have 1 null in it. The opposite table is optional, I have set the relation with ? on them so that it reflects, but this @unique getting added prevents the data from saving after the first record is added to the system.

model Intake {
   legalCase    LegalCase?         @relation("LegalCase_intake")
}

model LegalCase {  
  ...
  intakeId     String?         
  intake       Intake?         @relation(name: "LegalCase_intake", fields: [intakeId], references: [id])

After I run prisma apply the intakeId looks like this …

intakeId     String?         @unique
intake       Intake?         @relation(name: "LegalCase_intake", fields: [intakeId], references: [id])

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
michaelbullercommented, Jan 19, 2022

legalCase: input.legalCase != null ? {} : undefined I ended up patching my prisma call to check if the legal case is included in the call, and if not, dont send it through.

0reactions
janpiocommented, Jan 19, 2022

What is the query you are executing? Can you turn on https://pris.ly/d/debugging and https://pris.ly/d/logging and post the output here?

Read more comments on GitHub >

github_iconTop Results From Across the Web

What Is a One-to-One Relationship in a Database? - Vertabelo
A one-to-one relationship in a database is relatively uncommon. Check out these examples of 1:1 relationships in the real world and find out ......
Read more >
sql - How to implement one-to-one, one-to-many and many-to ...
In a one to one relationship, the join field should be unique in both tables. It is likely a PK on one table...
Read more >
Configure One-to-One relationship in Code First Entity ...
A one-to-zero-or-one relationship happens when a primary key of one table becomes PK & FK in another table in a relational database such...
Read more >
One-to-one relations - Prisma
One-to-one (1-1) relations refer to relations where at most one record can be connected on both sides of the relation. In the example...
Read more >
One-To-One and Many-to-Many Database Relationships
Each row in the Students table has a unique Student ID, and Classes have a unique Class ID. Each line thus becomes defined...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found