Can't figure out how to disconnect in prisma

I've been trying to figure out how to disconnect feed from user for like 2 hours now, and I can't figure out what part I'm getting wrong, my function looks like this:
removeUserFromFeed: protectedProcedure
.input(z.object({ feedId: z.string() }))
.query(async ({ ctx, input }) => {
// Remove user from feed
await ctx.prisma.user.update({
where: {
id: ctx.session.user.id,
},
data: {
Feeds: {
disconnect: [
{
id: input.feedId,
},
],
},
},
});
}),
removeUserFromFeed: protectedProcedure
.input(z.object({ feedId: z.string() }))
.query(async ({ ctx, input }) => {
// Remove user from feed
await ctx.prisma.user.update({
where: {
id: ctx.session.user.id,
},
data: {
Feeds: {
disconnect: [
{
id: input.feedId,
},
],
},
},
});
}),
But on the id: input.feedId, I get Type '{ id: string; }' is not assignable to type 'UserFeedsWhereUniqueInput'. Does anyone know how to make it, so it removes the Feed from the User? Here's my schema:
model User {
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime?
image String?
accounts Account[]
sessions Session[]
Feeds UserFeeds[]
Items UserItem[]
}

model UserFeeds {
feed Feed @relation(fields: [feedId], references: [id])
feedId String
user User @relation(fields: [userId], references: [id])
userId String
Folder String?

@@id([feedId, userId])
}

model Feed {
id String @id @default(cuid())
title String @unique
LogoUrl String
url String @unique
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
Users UserFeeds[]
items Item[]
}
model User {
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime?
image String?
accounts Account[]
sessions Session[]
Feeds UserFeeds[]
Items UserItem[]
}

model UserFeeds {
feed Feed @relation(fields: [feedId], references: [id])
feedId String
user User @relation(fields: [userId], references: [id])
userId String
Folder String?

@@id([feedId, userId])
}

model Feed {
id String @id @default(cuid())
title String @unique
LogoUrl String
url String @unique
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
Users UserFeeds[]
items Item[]
}
5 Replies
ZiiM
ZiiM2y ago
try it with disconnect like:
disconnect: {
id: input.feedId,
},

disconnect: {
id: input.feedId,
},

not a robot
not a robot2y ago
Unfortunately, that doesn't work and just returns Type '{ id: string; }' is not assignable to type 'Enumerable<UserFeedsWhereUniqueInput> | undefined'.
Brendonovich
Brendonovich2y ago
Having an explicit UserFeeds join table makes this tricky, on top of the fact that it's got a compound ID. What you're disconnecting in Feeds: isn't actually a Feed, so it doesn't know what the id field is. Instead you need to give it a feedId and userId, since they compose the primary key of UserFeeds, which is the actual model you're operating on.
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
not a robot
not a robot2y ago
Ok i did that and it worked thanks
Want results from more Discord servers?
Add your server