The error occurs because you are using the has operator on a field typed as Json in your Prisma schema. In Prisma, the has operator is only available for Scalar Lists (native database arrays like Int[] or String[]).
For a Json field, the operator you are looking for is array_contains.
Here are the two ways to fix this:
Option 1: Use array_contains (If field remains Json)
If your ganyu_options field must stay as a Json type in your schema.prisma, change your code to this:
typescript
where: {
OR: [
{ type: 1 },
{
ganyu_options: {
array_contains: low_number // Use array_contains for Json fields
}
},
],
status: 1,
},
Note: array_contains works on PostgreSQL and MySQL (for JSONB/JSON columns).
Option 2: Change Schema to Scalar List (Recommended)
If ganyu_options is always going to be a list of numbers, it is better to define it as an array in your schema.prisma. This makes it type-safe and allows you to use the has operator.
-
Update your
schema.prisma:prismamodel MiniArticle { id Int @id @default(autoincrement()) // Change from Json to Int[] ganyu_options Int[] status Int type Int }(Note: Native scalar lists like
Int[]are supported out-of-the-box by PostgreSQL and CockroachDB. If you are using MySQL, you must stick with Option 1). -
Run migration:
bashnpx prisma migrate dev -
Your original code will now work:
typescriptwhere: { OR: [ { type: 1 }, { ganyu_options: { has: low_number } }, // This works now! ], status: 1, },
Summary: Which one to choose?
- If using PostgreSQL and the data is always a list: Use Option 2 (Change to
Int[]). It is faster and more type-safe. - If using MySQL or the JSON structure is unpredictable: Use Option 1 (
array_contains).