Sequelize:获取Subquery / Raw Query作为include的模型

问题描述 投票:2回答:1

我已经阅读了Sequelize文档,但找不到任何有用的信息

我想要做的是在include中添加原始查询或自定义模型,是否可能?

model.Post.findAll({
            include: [{
                    model: model.User,
                    attributes: ['fullname', 'profilepic'],
                },
                {
                    model: model.PostComments,
                },
                {
                    model: "Raw Query"
                }
            ]
        }

我想要实现的是:

Select post_id, count(*) as total_likes from post_likes group by post_id

我无法通过简单地使用include实现这一点,所以我想要做的是从上面的查询创建一个表/模型,然后在include中使用它。

如果我在qazxsw poi中使用group,它从顶层给出group,我想仅仅为include表应用qazxsw poi。

如果发现令人困惑或不清楚,请告诉我。

node.js sequelize.js
1个回答
0
投票

您可以使用

group

要么

post_like
© www.soinside.com 2019 - 2024. All rights reserved.