【发布时间】:2016-04-12 00:30:27
【问题描述】:
我在 Sequelize 中制作了一个复杂的 findAll,其中包含很多 includes,就像这样。
const versions = yield Version.findAndCountAll({
order: [['createdAt', 'DESC']],
attributes: ['description', 'createdAt', 'id'],
include: [{
model: Section,
attributes: ['slug'],
where: { slug: section },
include: [{
model: Type,
attributes: ['slug'],
where: { slug: type },
include: [{
model: Group,
attributes: ['slug'],
where: { slug: group }
}]
}]
}]
});
结果如下:
{
"description": "Wow. Nice one.",
"createdAt": "2016-04-11T23:05:15.736Z",
"body": "hi",
"id": 10,
"Section": {
"slug": "ttyl",
"Type": {
"slug": "Test",
"Group": {
"slug": "python2",
}
}
}
}
它们嵌套的深度使结果有点令人不快。如果可能的话,我希望它更像这样
{
"description": "Wow. Nice one.",
"createdAt": "2016-04-11T23:05:15.736Z",
"body": "hi",
"id": 10,
"Section": "ttyl",
"Type": "Test",
"Group": "python2"
}
这可能吗?
【问题讨论】:
标签: javascript node.js sequelize.js