Can anyone please tell me what is wrong with this ...
# orm-help
k
Can anyone please tell me what is wrong with this query?
Copy code
_const_ _user = await _prisma_.user.findMany({
        where: {
          OR: [
            { email: {equals: _email_} },
            { phone: {equals: _phone_} }
          ]
        },
take: 1
for some reason result that don't satisfy either conditions
r
@KJReactor the query looks fine to me. Could you check if there’s data present that matches your query?
k
@Ryan Yes, I checked but it seems to be ignoring the where clause entirely. If anything it should return no results if not entries satisfy the conditions, I believe
r
@KJReactor it will return an empty array
[]
if no conditions are satisfied. Could you share your Prisma version so that I can reproduce?
k
yes, 2.7.1
πŸ‘ 1
r
Tried it with 2.7.1 and it works fine. Also I have added a query log so that you can view the queries in your terminal. You can check in your app if the
where
clause is executed in SQL or not.
k
Thanks
Do you think a mismatch between the cli and client cause this?
r
That could be possible
Could you try installing the same exact versions, run
prisma generate
and try?
k
Yes, I'm trying now
I upgraded both to v2.11.0 and getting this error:
Cannot read property 'filter' of undefined
r
I would need a reproduction here as I updated
@prisma/cli
and
@prisma/client
to 2.11.0 the test folder above and ran
prisma generate
which works fine.
You can check it in the same folder
k
Sorry I forgot to mention I got the error when attempting prisma generate
r
Are you facing the same error when you run it in the above project I sent? If not, try by deleting
node_modules
and running
npm i
again.
k
Yes, yours worked fine. I deleted node_modules and reinstalled but still get the same issue
r
Could you setup a reproduction if possible?
k
I don't know how I'd go about isolating it out of my project. Its quite big
Has "insensitiveFilters" been removed in 2.11.0? I'm getting an error that it's not known. Maybe I'll try updating to latest version?
r
It has been stabilized, so you do not need to add it in the
previewFeatures
block anymore.
πŸ‘ 1
2.11.0 is the latest as of now.
k
I still can't generate though
r
Could you share your datasource and generator block in
schema.prisma
?
k
Copy code
generator client {
  provider = "prisma-client-js"
  previewFeatures = ["insensitiveFilters"]
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}
@Ryan! I forgot to remove the previewFeatures from the schema and now its working again. Thanks alot, as usual you're a great help!!
πŸš€ 1
All remaining now is the where condition on findMany
r
Awesome πŸ˜„ Did you add the log option to PrismaClient to check the SQL?
k
Oh no, I didn't notice.
I had already deleted the test project. How do I do it?
r
Copy code
const prisma = new PrismaClient({
  log: ['query'],
})
This will log all queries generated by Prisma in your console. https://www.prisma.io/docs/about/faq#how-can-i-see-the-generated-queries-that-prisma-client-sends-to-my-database
k
Cool thanks.
πŸ‘ 1
so I switched findMany with findFirst and the exact same query worked. Its weird because although findFirst returned the correct row, findMany returned two with one not only being incorrect but the first in the returned array
πŸ€” 1
@Ryan I think I found the issue
In the SQL where clause there is a '...or 1=1)'
Could be the cause