Save foreign key prisma + trpc

Can't I just save a foreign key in this manner using trpc and prisma?
const client = await prisma?.customer.create({
data: {
companyId: company?.id,
userId: userId,
const client = await prisma?.customer.create({
data: {
companyId: company?.id,
userId: userId,
Currently getting this warning
Types of property 'userId' are incompatible.
Type 'string | undefined' is not assignable to type 'undefined'.
Type 'string' is not assignable to type 'undefined'.ts(2322)
Types of property 'userId' are incompatible.
Type 'string | undefined' is not assignable to type 'undefined'.
Type 'string' is not assignable to type 'undefined'.ts(2322)
This is my customer schema:
model Customer {
id String @id @default(cuid())
userId String
companyId String? @unique
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
Company Company[]
}
model Customer {
id String @id @default(cuid())
userId String
companyId String? @unique
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
Company Company[]
}
I just thought of saving the foreign key to have the relation.
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server