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

"unique" restriction in Prisma Schema #9

Open
olivodeveloper opened this issue Jul 29, 2024 · 0 comments
Open

"unique" restriction in Prisma Schema #9

olivodeveloper opened this issue Jul 29, 2024 · 0 comments

Comments

@olivodeveloper
Copy link

The @unique restrictions in SavedPost { userId and postId} generates an error when you try to save a post with different accounts, limiting the Save function to a single user.

Improved code:

model SavedPost {
id String @id @default(auto()) @Map("_id") @db.ObjectId
user User @relation(fields: [userId], references: [id])
post Post @relation(fields: [postId], references: [id])
userId String @db.ObjectId
postId String @db.ObjectId
createdAt DateTime @default(now())

@@unique([userId, postId])
}

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

No branches or pull requests

1 participant