Wondering if there's a straightforward way to dele...
# orm-help
c
Wondering if there's a straightforward way to delete a possibly orphaned record after disconnecting it? I have many-to-many user tagging and after disconnecting a tag from a user, I need to delete the tag if it's no longer referenced by other users. This is trivially easy with raw SQL but I couldn't find a way to do the delete with Prisma in one step:
Copy code
prisma.$transaction([
      prisma.user.update({
        where: { id: input.userId },
        data: {
          tags: {
            disconnect: [{ id }],
          },
        },
      }),
      prisma.$executeRaw`DELETE FROM "Tag" WHERE id NOT IN (SELECT "B" FROM "_UserToTag")`,
    ])
m
Like this maybe:
Copy code
prisma.tag.deleteMany(
 where: {
  users: {
   none: {}
  } 
 } 
);
1