how to delete a child object in prisma

how do i remove one follower from the followers array
model User {
id String @id @unique @default(cuid())
handle String @unique @default(cuid())
name String?
bio String?
email String? @unique
emailVerified DateTime?
createdAt DateTime @default(now()) @db.Timestamptz(3)
image String?
posts Post[]
accounts Account[]
sessions Session[]
comments Comment[]
likes Post[] @relation("likes")
followers User[] @relation("UserFollowers")
followersRelation User[] @relation("UserFollowers")
following User[] @relation("Userfollowing")
followingRelation User[] @relation("Userfollowing")
}
model User {
id String @id @unique @default(cuid())
handle String @unique @default(cuid())
name String?
bio String?
email String? @unique
emailVerified DateTime?
createdAt DateTime @default(now()) @db.Timestamptz(3)
image String?
posts Post[]
accounts Account[]
sessions Session[]
comments Comment[]
likes Post[] @relation("likes")
followers User[] @relation("UserFollowers")
followersRelation User[] @relation("UserFollowers")
following User[] @relation("Userfollowing")
followingRelation User[] @relation("Userfollowing")
}
my current function
unfollow: protectedProcedure.input(z.object({ userid: z.string(), pageid: z.string() })).mutation(async ({ input, ctx }) => {
const q1 = await ctx.prisma.user.update({
where: { id: input.userid },
data: {},
select: { following: { where: { id: input.pageid } } },
});
const q2 = await ctx.prisma.user.update({
where: { id: input.pageid },
data: { },
});

return { q1, q2 };
}),
unfollow: protectedProcedure.input(z.object({ userid: z.string(), pageid: z.string() })).mutation(async ({ input, ctx }) => {
const q1 = await ctx.prisma.user.update({
where: { id: input.userid },
data: {},
select: { following: { where: { id: input.pageid } } },
});
const q2 = await ctx.prisma.user.update({
where: { id: input.pageid },
data: { },
});

return { q1, q2 };
}),
1 Reply
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server