Bård
11/02/2021, 1:44 PMmodel User {
id String @id @default(cuid())
name String?
email String? @unique
role Json @default("[ \"user\" ]")
emailVerified DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
Account Account[]
Session Session[]
profile Profile?
seed Seed[]
weeklyWinner WeeklyWinners?
userQuestions UserQuestions[]
}
model UserQuestions {
id Int @id @default(autoincrement())
answer Json?
submitted Boolean? @default(false)
uid String
questionnaireId Int?
user User @relation(fields: [uid], references: [id])
questionnaire Questionnaire? @relation(fields: [questionnaireId], references: [id])
@@unique([uid, questionnaireId])
}
Considering these tables in my schema, i'm trying to get all users which have a relation to UserQuestions with the prop "submitted" to true.
This is my query:
prisma.user.findMany({
where: {
userQuestions: {
every: {
submitted: true,
},
},
},
select: {
email: true,
userQuestions: true,
name: true,
profile: true,
},
});
For some reason, this returns ALL users, including users who have no relation to UserQuestions. Any idea what is wrong here?Ryan
11/02/2021, 1:45 PMsome
instead of every
.Bård
11/02/2021, 1:52 PMBård
11/02/2021, 1:53 PMBård
11/02/2021, 2:02 PMRyan
11/02/2021, 2:03 PMevery
should be used.Ryan
11/02/2021, 2:03 PMBård
11/02/2021, 2:04 PMprisma.user.findMany({
where: {
userQuestions: {
every: {
submitted: true,
},
some: {},
},
},
select: {
email: true,
userQuestions: true,
name: true,
profile: true,
},
});