.upsert when no way to track query/track unique identifier?
I have a (plan to) setup where a user can like multiple posts. This can be done once per day.
Here is my structure, my logic being that I can query the
where: { serverID, userID}
and get the results of previous.
Here's where I am misunderstanding, upsert
only allows for one where
entry? But I would need to query both in order to verify the correct entry.
This is the error I get inside VSCode:
3 Replies
The error when attempting to trigger the query:
I guess my question is 2 fold:
1) Can I use upsert/this design database? Or do I need to rethink my approach.
2) If I can make this work, what's the correct way to resolve this.
From what I understand, older versions of Prisma only expose unique fields (see the type
UserWhereUniqueInput
) on your models as fields in the where
object when upsert
is being used.
According the docs: https://www.prisma.io/docs/reference/api-reference/prisma-client-reference#filter-on-non-unique-fields-with-userwhereuniqueinput, this behaviour was changed in Prisma >= 4.5.0 so you can reference non-unique fields in the where
object.Thank you!