首页 > 解决方案 > 无法使用 dgraph-orm 查询嵌套关系

问题描述

我正在使用dgraph-orm 来获取嵌套的关系值,但它适用于单级而不是多级。我正在获取页面详细信息,但无法获取页面的头像。

这是我的片段:

let posts = await PagePost.has('page_id', {
      filter: {
        page_id: {
          uid_in: [page_id]
        }
      },
      include: {
        page_id: {
          as: 'page',
          include: {
            avatar: {
              as: 'avatar'
            }
          }
        },
        owner_id: {
          as: 'postedBy'
        }
      },
      order: [], // accepts order like the above example
      first: perPage, // accepts first
      offset: offset, // accepts offset
    });

我没有得到属性 page_id 的头像:

 {
            "uid": "0x75b4",
            "title": "",
            "content": "haha",
            "created_at": "2019-09-23T08:50:52.957Z",
            "status": true,
            "page": [
                {
                    "uid": "0x75ac",
                    "name": "Saregamaapaaaa...",
                    "description": "This a is place where you can listen ti thrilling music.",
                    "created_at": "2019-09-23T06:46:50.756Z",
                    "status": true
                }
            ],
            "postedBy": [
                {
                    "uid": "0x3",
                    "first_name": "Mohit",
                    "last_name": "Talwar",
                    "created_at": "2019-07-11T11:37:33.853Z",
                    "status": true
                }
            ]
        }

orm中是否支持多级字段查询?

标签: node.jsormgraph-databasesdgraph

解决方案


ORM 本身存在一些问题,它无法识别多级包含的正确模型名称并生成错误的查询。

在 1.2.4 版本中修复了相同的问题,请运行npm update dgraph-orm --save以更新您的 DgraphORM。

谢谢你的问题。


推荐阅读