I have 2 tables, Challenges & UserResponse defined as so with prisma:
model Challenge {
id Int @id @default(autoincrement())
title String
description String
createdById String
createdBy User @relation(fields: [createdById], references: [id])
options Option[]
UserResponse UserResponse[]
}
model UserResponse {
id Int @id @default(autoincrement())
userId String
challengeId Int
optionId Int
challenge Challenge @relation(fields: [challengeId], references: [id])
option Option @relation(fields: [optionId], references: [id])
user User @relation(fields: [userId], references: [id])
@@unique([userId, challengeId])
}
Using supabase I would like to get all challenges for whom there is no UserResponse with userId: 123.
I came up with this query, but it only filters UserResponses not Challenges:
const { data: challenges, error } = await supabaseClient
.from('Challenge')
.select('*, Option(*), UserResponse(userId)')
.neq('UserResponse.userId', userId);
Basically, I don’t want the users to see the challenges that they have already responded to.