Hi guys, I need assistance in one aspect of Prisma...
# orm-help
e
Hi guys, I need assistance in one aspect of Prisma that I can't see to crack. I have a model with two types defined as follows: type User { id: @ID email: String! password: String! bio: Bio! contacts: [Contact!]! } type Contact { id: @ID bio: Bio! } Each user can have MANY contacts and each contact can belong to MANY users. When inserting contacts for users, how can I verify that I am not creating duplicate relationships? In other words, check for existence of many to many relationships
đź‘€ 2
m
I don't know which database are you using and if you are able to check with prisma, but I have a similar case and I have a unique constraint in the postgres table, if you're trying to insert a duplicate row, it throws an error.
r
I’m not sure if there are any built in functionality that you can use directly on Prisma schema level. In your case I would handle it in mutation resolver: 1. Define bidirectional relation between both entities 2. Use upsert method from Prisma Clien to update user contacts (or in other way around) Another alternative: manual check if exists: https://github.com/prisma/prisma/issues/2194 It would be great to hear any better suggestions.