TRPC and PRISMA id type

Currently im trying to delete a object using id in prisma using trpc.
delete: privateProcedure.input(
z.object({
id: z.string().cuid(),
}),
).mutation(async ({ ctx, input }) => {
const post = await ctx.prisma.teacher.delete({
where: {
id: input.id,
},
});
}),
delete: privateProcedure.input(
z.object({
id: z.string().cuid(),
}),
).mutation(async ({ ctx, input }) => {
const post = await ctx.prisma.teacher.delete({
where: {
id: input.id,
},
});
}),
but im getting this error
❌ tRPC failed on teachers.delete: [
{
"code": "invalid_type",
"expected": "object",
"received": "string",
"path": [],
"message": "Expected object, received string"
}
]
❌ tRPC failed on teachers.delete: [
{
"code": "invalid_type",
"expected": "object",
"received": "string",
"path": [],
"message": "Expected object, received string"
}
]
Here is the schema
model Teacher {
id String @id @default(cuid())
createdAt DateTime @default(now())

name String
email String
role String
phone String
dob String

authorId String
}
model Teacher {
id String @id @default(cuid())
createdAt DateTime @default(now())

name String
email String
role String
phone String
dob String

authorId String
}
16 Replies
Yiannis
Yiannis2y ago
If you remove the .cuid from the input schema does it work? Seems like you can do input.id.somethingElse
elpupper
elpupperOP2y ago
Nope i tried The input.id is a string
Yiannis
Yiannis2y ago
Id you hardcode a string does it work? Like go to your primes studio and copy the id
elpupper
elpupperOP2y ago
But id: is expecting a object idk why Thats what im doing I have a button to create a teacher I get the teacher id And then button to delete the teacher from id
Yiannis
Yiannis2y ago
I mean don’t use your schema input at all literally type where: { id: theIdYouGotFromPrismaStudioGoesHere } Just to see if that’s the issue at all
elpupper
elpupperOP2y ago
Ah Same error 😭😭
Yiannis
Yiannis2y ago
Give me 15 minutes to be on my desk so I can try recreate this Oh Can you show where you are calling the mutation? This is a trpc error not a prisma one Looks like you a doing delete.mutate(id) instead of delete.mutate({id: id})
elpupper
elpupperOP2y ago
Im doing the first one yes Its 6:20 am i just turned off my pc
Yiannis
Yiannis2y ago
Yeah that should be erroring in the code Like at your editor
elpupper
elpupperOP2y ago
Alright then perfect ima do that when i wakeup in a few hours
Yiannis
Yiannis2y ago
If you remember drop a line on here just for closure
elpupper
elpupperOP2y ago
Ah u defo right I remember following the chirp guide i think i just missed that Wym
Yiannis
Yiannis2y ago
Like if this fixes the problem let us know here in case anyone else has something similar
elpupper
elpupperOP2y ago
worked 😎
Yiannis
Yiannis2y ago
Don’t forget to do this
elpupper
elpupperOP2y ago
Ok
Want results from more Discord servers?
Add your server