Checking for an empty array as a column in a row

I have a schema with a column called "creators" which is an array. I want to only return rows that have >0 items in the array
const result = await context.entities.MyEntityTable.findMany({
where: {
id: { in: inputString.split(',').map((id: string) => +id) },
creators: {
isEmpty: false,
},
},
});
const result = await context.entities.MyEntityTable.findMany({
where: {
id: { in: inputString.split(',').map((id: string) => +id) },
creators: {
isEmpty: false,
},
},
});
However, this seems to be wrong. It says I can only use some, none or every.
1 Reply
kapa.ai
kapa.ai3mo ago
Hi @CamBlackwood. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- You're correct that Prisma (and therefore Wasp, which uses Prisma under the hood) does not support an isEmpty filter for array (relation) fields. Instead, you should use the some filter to check if the array/relation contains at least one item. For example, if creators is a relation to another entity, you can write:
const result = await context.entities.MyEntityTable.findMany({
where: {
id: { in: inputString.split(',').map((id) => +id) },
creators: {
some: {}, // This checks that there is at least one related creator
},
},
});
const result = await context.entities.MyEntityTable.findMany({
where: {
id: { in: inputString.split(',').map((id) => +id) },
creators: {
some: {}, // This checks that there is at least one related creator
},
},
});
This will return only the rows where the creators array/relation is not empty. If creators is a scalar array (e.g., an array of strings or ints), Prisma currently does not support filtering by array length directly. In that case, you would need to fetch the rows and filter them in your application code. The knowledge sources confirm that for relation fields, you should use some, none, or every, and not isEmpty. There is no mention of isEmpty being supported, and the error message you received is expected in this context. For more on how to use entities and queries in Wasp, see the official docs. If you need to filter by array length for scalar arrays, unfortunately, the knowledge sources do not provide a built-in solution for this in Wasp/Prisma. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @CamBlackwood, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?

Did you find this page helpful?