Handling duplicates with trpc
Lets say I have an User in Prisma database that has a Coin[] array in his model.
Currently I'm doing something like this to display table of all items:
It works but the problem is that this way, person can add same items multiple times to this array since they all have unique ids. But if I try to make id not unique then if one user adds an item to his array, the rest cant. So im looking for a better way to handle this. Prisma schema for context:
11 Replies
You can make the combination of
Coin
's id and a User
's id unique maybe? Not sure if I understand the question
Or make the name unique if you want people to only be able to create a coin that doesn't already exist? 🤔I thought about this but the problem is that Im currently displaying a table of coins and I want users to be able to add them to their favorites. But if one user adds a Bitcoin for example the others cant which sucks
Ah I get what you are doing
is there a way to write something like this in prisma?
You can make a combination of fields unique in Prisma
You can add a table in between
Prisma
Unique constraints and indexes with Prisma and MySQL
Learn how to configure unique constraints and indexes with Prisma and MySQL by following the step-by-step instructions in this practical guide.
Look for @@unique
Ill check it, thanks guys
Idk maybe something like this if I get what you are trying to do
ill try it out, thanks!