[英]How can I filter a table by a nested array of objects property with prisma?
So I have a table with a json field, and that field has a nested field which is an array of objects.所以我有一个带有 json 字段的表,该字段有一个嵌套字段,它是一个对象数组。 I'm trying to filter the rows by the nested array of objects to basically get rows where the nested array of object contains an object with a particular value.我正在尝试按嵌套对象数组过滤行,以基本上获取嵌套对象数组包含具有特定值的对象的行。 I keep getting 0 results.我一直得到 0 个结果。 The database is PostgreSQL.数据库是 PostgreSQL。 Any help will be greatly appreciated.任何帮助将不胜感激。
So the table this schema:所以表这个模式:
model Requests {
...,
properties Json?
}
The format of the saved properties is like this:保存的属性格式如下:
{
multiple: true,
receivers: [
{
name: '',
id: 1,
status: 'Pending'
},
{
name: '',
id: 5,
status: 'Pending'
},
]
}
And this is my query:这是我的查询:
const requests = await prisma.requests.findMany({
where: {
AND: [
{
'properties': {
path: ['receivers', '$[*].id'],
array_contains: 5,
}
},
{
'properties': {
path: ['receivers', '$[*].transactionStatus'],
array_contains: 'Pending'
}
}
]
}
})
It does not work, since you're using PostgreSQL and Prisma doc says:它不起作用,因为您使用的是 PostgreSQL,而 Prisma 文档说:
Filtering on object key values within an array is only supported by the MySQL仅 MySQL 支持过滤数组中的对象键值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.