【发布时间】:2018-04-25 02:00:09
【问题描述】:
我正在使用 Express 构建一个应用,Postgres 作为 db,Sequelize 作为 ORM。
这是我得到的回复:
{
"user": {
"user_name": "John",
"post": [
{
"id": 1,
"created_at": "2018-04-16T22:52:59.054Z",
"post_titles": [
{
"title_id": 3571
},
{
"title_id": 3570
},
{
"title_id": 3569
}
]
},
],
}
}
如何计算帖子中有多少标题?
我有 4 个模型:User,hasMany Posts Post,有很多 Titles 到 PostTitles Title PostTitle
这是我的查询:
User.findOne({
where: { id: req.params.id },
attributes: ['id', 'user_name'],
include: [
{ model: Post,
attributes: ['id', 'created_at'],
include: {
model: PostTitles,
attributes: ['title_id']
}
}
]
})
谢谢!
【问题讨论】:
标签: javascript postgresql express sequelize.js