Node.js 如何在Sequelize中对关联项进行分页?

Node.js 如何在Sequelize中对关联项进行分页?,node.js,typescript,sequelize.js,Node.js,Typescript,Sequelize.js,我有两个表,它们之间有多对多关系。在我的例子中,我试图获取与租户关联的用户,但我希望对用户的结果进行分页。我尝试在include块中使用limit,但这不起作用。我收到一个错误,说仅支持多个关联,包括.separate 这就是两国关系的样子 User.belongsToMany(Tenant, { as: 'tenants', through: UserTenant, foreignKey: 'userId' }); Tenant.belongsToMany(User, { a

我有两个表,它们之间有多对多关系。在我的例子中,我试图获取与租户关联的用户,但我希望对用户的结果进行分页。我尝试在include块中使用
limit
,但这不起作用。我收到一个错误,说
仅支持多个关联,包括.separate

这就是两国关系的样子

User.belongsToMany(Tenant, {
  as: 'tenants',
  through: UserTenant,
  foreignKey: 'userId'
});

Tenant.belongsToMany(User, {
  as: 'users',
  through: UserTenant,
  foreignKey: 'tenantId'
});
查询如下所示:

const tenant = (await Tenant.findOne({
      where: {
        tenantId,
        isDeleted: false
      },
      attributes: {
        exclude: [modelDictionary.tenant.isDeleted, modelDictionary.tenant.tenantId, modelDictionary.tenant.name, modelDictionary.tenant.connectionInfo]
      },
      include: [
        {
          model: User,
          where: { isDeleted: false },
          as: 'users',
          required: true,
          attributes: { exclude: [modelDictionary.user.isDeleted] },
          through: {
            where: {
              isDeleted: false
            },
            attributes: []
          }
        }
      ],
      order : [[ 'users', modelDictionary.user.lastName , 'ASC NULLS FIRST']]
    })) as any;
有没有办法解决这个问题