```model User { id String @i...
# orm-help
b
Copy code
model 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:
Copy code
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?
1
r
@Bård 👋 You need to use
some
instead of
every
.
b
Users can have up to 3 UserQuestions, I want to only find users who have submitted on all 3. Wouldn't some just give me people who has submitted at least 1?
Isn't the point of every to get users with every UserQuestion-relation submitted: true?
@Ryan Isn't my use-case very similiar to the docs here: https://www.prisma.io/docs/reference/api-reference/prisma-client-reference#every Cheers for the help 🙂
r
If you want users who have submitted, then yes
every
should be used.
I think every also returns the Users who don’t have a relation i.e. Question at all. Let me check and verify.
b
@Ryan, you are correct! I edited my query to include an empty object on some. This seems to filter out the users with no relation.
Copy code
prisma.user.findMany({
  where: {
    userQuestions: {
      every: {
        submitted: true,
      },
      some: {},
    },
  },
  select: {
    email: true,
    userQuestions: true,
    name: true,
    profile: true,
  },
});
💯 1
1