【发布时间】:2023-01-29 16:39:51
【问题描述】:
我目前正在开发一个端点,我想从 4 个不同的表中返回一个对象。我从 sequelize 中获取 JSON 格式的每个表的记录。我有位置、服务、员工和租户。如何将它们合并为一个对象但嵌套。 例如: 我从 sequelize for staff 获得的数据:
{
"id": 2,
"profession": "Dentist",
"note": "Good Man",
"holidays": "Saturday",
"specialDays": null,
"createdAt": "2023-01-27T14:23:52.000Z",
"updatedAt": "2023-01-27T14:23:52.000Z",
}
所有其他数据都采用类似的格式。但我想合并它们以返回类似的内容:
{ staff:{
"id": 2,
"profession": "Dentist",
"note": "Good Man",
"holidays": "Saturday",
"specialDays": null,
"createdAt": "2023-01-27T14:23:52.000Z",
"updatedAt": "2023-01-27T14:23:52.000Z",},
location:{
"id": 1,
"name": "Branch 1",
"address": "37 Automatic Handling",
"description": "This is our main branch",
"latitude": "564233",
"longtitude": "4441256",
"visible": true,
"createdAt": "2023-01-27T14:05:37.000Z",
"updatedAt": "2023-01-27T14:05:37.000Z",
}
}
【问题讨论】:
标签: javascript json express sequelize.js