麻烦看下这段sequelize(ORM)代码,有SQL?
这是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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论