Theo's Typesafe CultTTC
Theo's Typesafe Cult4y ago
1 reply
shu

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")
}


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 };
  }),
Was this page helpful?