I am trying to filter by a key and value inside a ...
# orm-help
a
I am trying to filter by a key and value inside a JSON field (using Postgres), reading this https://www.prisma.io/docs/concepts/components/prisma-client/working-with-fields/working-with-json-fields#json-object-arrays So I adapted my code to try to find a value inside a JSON field like this:
Copy code
const application = await prisma.application.findFirst({
    where: {
      id: applicationId,
      tasks: {
        array_contains: [{ keyName: taskKeyName }],
      },
    },
  });
basically I want to filter inside the JSON
tasks
field (which is an array) for a value inside
keyName
but I keep
array_contains
is unknown, I've tried to use
equals
but I assume that only returns data if all the array key value matches. I am a bit lost and I'm not sure why it doesn't work 😞
r
@Angelo 👋 Could you share your
schema.prisma
?
a
sure, sorry for the delay
Copy code
model Application {
  id               String             @id @default(uuid())
  tasks            Json
}
r
@Angelo 👋 Works fine for me. Have you added
filterJson
to the
previewFeatures
in your
schema.prisma
?
Copy code
generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["filterJson"]
}
And then run
prisma generate
. I just tried and it works fine for me.
a
I thought I didn't need because my Prisma version, but I'm pretty sure that's the problem, thank you
👍 1