mapping a column in model to another model
I have nextauth with github
I want github usernames to be fetched so I can display them alongside comments.
working state of my
schema.prisma
:
I think I'm supposed to add another field for a relation between User and Comment tables? see that I added userName
but I get an error -> Error parsing attribute "@relation": The argument references
must refer to a unique criterion in the related model. Consider adding an @@unique([id, name])
attribute to the model User
.
and I'm kinda lost1 Reply
I think I figured it out but will prob break?
I defined a compound unique constraint for User id and name:
so now my Comment can have two fields that refer to user:
then my session callback is updated to add github user.name to session user.name:
... however see that logical OR -- I don't want it. I tried to find how to update
user
type to guarantee it will return name
then I had to update my router where it used to just rely on userId. now I have to specify a user
object -> create
object -> name
:
if I'm missing some things please let me know!