简体   繁体   English

如何通过具有棱镜的嵌套对象属性数组过滤表?

[英]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.

相关问题 按属性过滤嵌套对象 - Filter nested objects by property 如何在多个条件下过滤嵌套的对象数组? - How do I filter nested array of objects on multiple conditions? 如何通过其 Date 属性过滤对象数组,每天仅显示最后存储的对象? - How can I filter an array of objects by its Date property showing only last stored objects per each day? 我如何过滤并返回嵌套的对象数组? - How i can filter and return a nested array of object? 如何将对象数组过滤到 MongoDB 文档中 - How can I filter array of objects into MongoDB Document 如何将对象推送到 mongoDB 和 expressjs 中的嵌套对象数组 - How can I push an object to a nested array of objects in mongoDB and expressjs 如何过滤再次包含 JSON 对象数组的 JSON 对象数组? - How can i filter an array of JSON objects which again contain an array of JSON objects? 如何使用 GraphQL 查询中的字段通过 Prisma 执行嵌套读取? - How can I use the fields in a GraphQL query to perform nested reads with Prisma? 如果过滤键可以有任何类型的值,我如何过滤数组中的唯一对象? - How do I filter the unique objects from an array if the filter key can have any type of value? Typeescript如何根据特定属性是否存在过滤对象数组 - Tyepescript how to filter an array of objects depending on a specific property exists or not
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM