Skip to content
This repository has been archived by the owner on Jan 14, 2021. It is now read-only.

findMany / OR accepts non-array value - should only accept arrays #657

Closed
mhwelander opened this issue Apr 21, 2020 · 3 comments
Closed
Labels
kind/discussion Discussion is required. tech/typescript Issue for tech TypeScript.
Milestone

Comments

@mhwelander
Copy link

Bug description

findMany accepts a non-array value when filtering with OR even though OR requires an array.

The following is 'allowed' but does NOT return the expected results:

  const orIncorrect = await prisma.post.findMany({
    orderBy: {
      id: 'asc'
    },
    where: {
      OR: {
        title: {
          equals: "Prisma makes databases easy"
        },
        authorId: {
          equals: 2
        }
      }
    }
  });

Correct syntax is:

const orCorrect = await prisma.post.findMany({
   orderBy: {
     id: 'asc'
   },
   where: {
     OR: [{
       title: {
         equals: "Prisma makes databases easy"
       },
     }, {
       authorId: {
         equals: 2
       }
     }]
   }
 })

Expected behavior

OR does not accept non-array value.

Prisma information

Schema from TypeScript starter project (https://www.prisma.io/docs/getting-started/quickstart?lang=typescript):

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "sqlite"
  url      = env("DATABASE_URL")
}

model Post {
  authorId  Int?
  content   String?
  id        Int     @default(autoincrement()) @id
  published Boolean @default(false)
  title     String
  User      User?   @relation(fields: [authorId], references: [id])
}

model User {
  email   String   @unique
  id      Int      @default(autoincrement()) @id
  name    String?
  Post    Post[]
  Profile Profile?
}

model Profile {
  bio    String?
  id     Int     @default(autoincrement()) @id
  userId String  @unique
  User   User    @relation(fields: [userId], references: [id])
}

Environment & setup

  • Prisma version: 2.0.0-beta.2
@pantharshit00 pantharshit00 added bug/2-confirmed We have confirmed that this is a bug. kind/bug A reported bug. process/candidate Candidate for next Milestone. labels Apr 21, 2020
@janpio janpio added this to the Beta 4 milestone Apr 21, 2020
@janpio janpio added team/product tech/typescript Issue for tech TypeScript. and removed process/candidate Candidate for next Milestone. labels Apr 21, 2020
@timsuchanek timsuchanek added kind/discussion Discussion is required. and removed bug/2-confirmed We have confirmed that this is a bug. kind/bug A reported bug. labels Apr 22, 2020
@timsuchanek
Copy link
Contributor

Thanks for reporting!
Although the behavior is very ugly, it's the expected behavior right now.
Therefore I remove the bug label.
This is for sure something we can change, just a bit of more thinking and product work is needed.

@nikolasburk
Copy link
Member

Here's the relevant internal discussion.

@timsuchanek
Copy link
Contributor

Thanks a lot for reporting 🙏
This issue is fixed in the latest alpha version of @prisma/cli.
You can try it out with npm i -g @prisma/cli@alpha.

In case it’s not fixed for you - please let us know and we’ll reopen this issue!

@janpio janpio removed this from the Beta 9 milestone Jun 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/discussion Discussion is required. tech/typescript Issue for tech TypeScript.
Projects
None yet
Development

No branches or pull requests

8 participants