Halvor
08/08/2021, 6:19 PMmodel User {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
username String @unique
password String
userUUID UserUUID?
}
model UserUUID {
id String @id @default(uuid())
user User @relation(fields: [userId], references: [id])
userId Int @unique
}
I want to add an entry to UserUUID if one is not present for the provided username, how can i achieve that?
I tried with the following but it complains about not being able to uniquely identify a user.
await prisma.userUUID.upsert({
where: {
user: {
username: username.toLowerCase()
}
},
update: {},
create: {
user: {
connect: {
username: username.toLowerCase()
}
}
}
});
Anyone knows how i can acheive this? Reason for having a UserUUID is that it should not always be present for every user, only users that have activated that feature.Ryan
08/09/2021, 7:48 AMusername
passed is correct and present in the database?Halvor
08/09/2021, 8:29 AMHalvor
08/09/2021, 8:32 AMRyan
08/09/2021, 8:43 AMupsert
will only work for the field in the same model. It cannot reference the @unique
fields in another model.Halvor
08/09/2021, 8:47 AMRyan
08/09/2021, 10:20 AMcreate
.Halvor
08/09/2021, 11:20 AMHalvor
08/09/2021, 2:43 PMCompilation error in /srv/rest/src/services/gator/gatorCommon.ts
rest_1 | [ERROR] 14:42:26 ⨯ Unable to compile TypeScript:
rest_1 | src/services/gator/gatorCommon.ts(25,13): error TS2322: Type '{ user: { username: string; }; }' is not assignable to type 'UserUUIDWhereUniqueInput'.
rest_1 | Object literal may only specify known properties, and 'user' does not exist in type 'UserUUIDWhereUniqueInput'.
Halvor
08/09/2021, 8:38 PMwhere: {
user: {
username: "someusername"
}
}
Halvor
08/09/2021, 9:02 PMHalvor
08/11/2021, 2:31 PM