麻烦看下这段sequelize(ORM)代码,有SQL?

发布于 2022-09-03 01:09:55 字数 1170 浏览 17 评论 0

这是ORM代码

models.User.findAndCountAll({
    include: [{
        model: models.Role,
        through: {
            attributes: ['id', ['name', 'rolename'], 'desc']
        }
    }],
    attributes: ['id', ['name', 'username']],
    raw: true,
    limit: 20,
    offset: 0
});

这是SQL

SELECT count(*) AS "count" FROM "User" AS "user";

SELECT "user".*, 
"roles"."id" AS "roles.id", 
"roles"."name" AS "roles.name", 
"roles"."desc" AS "roles.desc", 
"roles"."create_by" AS "roles.create_by", 
"roles"."createdAt" AS "roles.createdAt", 
"roles"."updatedAt" AS "roles.updatedAt", "roles.userRole"."createdAt" AS "roles.userRole.createdAt", "roles.userRole"."updatedAt" AS "roles.userRole.updatedAt", "roles.userRole"."userId" AS "roles.userRole.userId", "roles.userRole"."roleId" AS "roles.userRole.roleId" FROM (SELECT "user"."id", 
"user"."name" AS "username" FROM "User" AS "user" LIMIT 20 OFFSET 0) 
AS "user" LEFT OUTER JOIN 
("UserRole" AS "roles.userRole" INNER JOIN "Role" AS "roles" ON "roles"."id" = "roles.userRole"."roleId") 
ON "user"."id" = "roles.userRole"."userId"

查询role表后,却没有执行attributes里的过滤条件

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文