这是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里的过滤条件
光阴似箭催人老,日月如移越少年。