Chris Valentine
Chris Valentine
PPrisma
Created by Chris Valentine on 9/26/2024 in #help-and-questions
Property does not exist on type..but it clearly does.
No description
4 replies
PPrisma
Created by Chris Valentine on 5/2/2024 in #help-and-questions
I feel this is simple but I fear i've just been at it too long I'm starting to not see straight.
I have a parent record with a many to many relationship with a child, such as:
model User {
id String @id @default(cuid())
name String?
username String? @unique

badges UserBadges[]
}

model Badge {
id String @id @default(cuid())
name String @unique
users UserBadges[]
}

model UserBadges {
id String @id @default(cuid())
userId String
badgeId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
badge Badge @relation(fields: [badgeId], references: [id], onDelete: Cascade)
}
model User {
id String @id @default(cuid())
name String?
username String? @unique

badges UserBadges[]
}

model Badge {
id String @id @default(cuid())
name String @unique
users UserBadges[]
}

model UserBadges {
id String @id @default(cuid())
userId String
badgeId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
badge Badge @relation(fields: [badgeId], references: [id], onDelete: Cascade)
}
i want to insert (or upsert). a new User. for that user i will have a list of badges by name only, i will not know the id of them at that point, but they are sure to already exist in the DB.
const user = await prisma.user.upsert({
where: {email: userRecord.email},
update: {
username: userRecord.username,
name: userRecord.name,
badges: {
connect: {
id: userRecord.badges.map((badge: any) => {
return {name: badge.name}
})
}
}
},
create: {
username: userRecord.username,
name: userRecord.name,
badges: userRecord.badges,
}
})
const user = await prisma.user.upsert({
where: {email: userRecord.email},
update: {
username: userRecord.username,
name: userRecord.name,
badges: {
connect: {
id: userRecord.badges.map((badge: any) => {
return {name: badge.name}
})
}
}
},
create: {
username: userRecord.username,
name: userRecord.name,
badges: userRecord.badges,
}
})
around here typescript just yells at me. How do I get this working and connect them by name instead of id?
1 replies