Sequelize嵌套数据结构
问题描述:
我想使用sequelize & nodeJS在我们的postgresql数据库上进行查询。Sequelize嵌套数据结构
除了模型深层嵌套关系的结构之外,这一切都工作正常。
我的例子:
{
model: this.Parent,
as: 'Parent',
include: [
{
model: this.Child,
as: 'child',
include: [
{
model: this.nestedChild,
as: 'nestedChild',
},
],
},
],
},
为孩子和nestedChild在“包括”对象返回的数据,问题是,nestedChild不再是“关系”的对象的孩子,而不是它的其中一个参数。 例如:
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
}
]
答
原来,嵌套关系查询很好。这是那个步骤之后的JSON序列化程序,它没有定义正确的结构,因此一旦将响应发送到前端,它就会丢失。