【发布时间】:2020-10-07 00:52:18
【问题描述】:
我有 Content 模型,它有很多子 ContentImage 项目,像这样;
const content = await db.Content.findOne({
where: {
permalink: req.params.permalink
},
include: [{
model: db.ContentImages
}]
raw: true
});
如您所知raw:true 将 SequelizeInstance 隐蔽到对象模型。在这一点上我有一些问题。
如果我使用raw:true,json 模型会这样显示;
{
"id": 4706,
"name": "Content Title",
"content": "Content detail",
"t_content_images.id": 7633,
"t_content_images.content_id": 4706,
"t_content_images.image": "content-image-1.jpg",
"t_content_images.order_no": 1
}
因为expressjs,我需要like这个模型而不是SequelizeInstance;
{
"id": 4706,
"name": "Content Title",
"content": "Content detail",
"t_content_images": {
"id": 7633,
"content_id": 4706,
"image": "content-image-1.jpg",
"order_no": 1
}
}
另一个问题,我有多个内容图像,如果我使用上面的第一个示例,它只返回第一个内容图像。
【问题讨论】:
标签: node.js sequelize.js