简体   繁体   English

序列化嵌套数据结构

[英]Sequelize nested data structure

I'm trying to make a query on our postgresQL database using sequelize & nodeJS. 我正在尝试使用sequelize和nodeJS在我们的postgresQL数据库上进行查询。

It's all working fine apart from the structure of the deeply nested relationships for the model. 除了该模型的深层嵌套关系的结构之外,所有这些都工作正常。

My example: 我的例子:

{
      model: this.Parent,
      as: 'Parent',
      include: [
        {
          model: this.Child,
          as: 'child',
          include: [
            {
              model: this.nestedChild,
              as: 'nestedChild',
            },
          ],
        },
      ],
    },

The data for the child and nestedChild is returned in the 'included' object, the problem is that the nestedChild is no longer in 'relationships' object for the child, instead it's one of it's params. 子项和nestedChild的数据在“ included”对象中返回,问题是子项nestedChild不再在该子项的“ relationships”对象中,而是它的参数之一。 Example: 例:

data: [proper array of Parent elements with defined 'child' relationship in 'relationships' object],
included: [
    {
        attributes: {
            nested-child: {
            (here are properties for my nestedChild)
            }
        },
    relationships: <------ this is missing, and should include my nestedChild
    }
]

Turned out the nested relationship query is fine. 原来嵌套关系查询很好。 It was the JSON serializer after that step that didn't have the proper structure defined therefore it was missing once the response was sent to front-end. 该步骤之后的JSON序列化程序未定义正确的结构,因此一旦将响应发送到前端,它就会丢失。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM