node.js - 带有偏移量和限制的嵌套包含 Sequelize

标签 node.js sequelize.js

有人成功地在 Sequelize 中使用嵌套包含以及限制和偏移吗?我正在尝试使用 Sequelize 实现服务器端分页,任何人都可以向我展示任何引用。我正在使用 Sql Server 数据库。当我尝试执行此操作时,我看到查询正在转换为子查询以及联接。有人拿到了吗

{where: query.activity,
        attributes: [...activityAttributes, 'LastModifiedUserID', 'LastModifiedDateUTC', 'SPIStatus'],
        include: [
            {
                model: Issue,
                where: query.issue,
                attributes: issueAttributes,
                include: [{
                    model: Product,
                    where: query.product,
                    attributes: productAttributes
                },
                    {
                        model: IssueExtendedAttribute,
                        where: {$and: query.issueExtendedAttributes},
                        required: !!query.issueExtendedAttributes
                    }]
            }],
           offset: 10,
           limit: 10}  

最佳答案

您需要添加

subQuery: false;

例如:

{
    subQuery: false,
    where: queryObj,
    include: [{
      model: db.A,
      where: AQueryObj,
      include:[{
        model: db.B,
        where: BQueryObj
      },{
        model: db.C,
        where: CQueryObj
      }]
    }],
    offset: offset,
    limit: limit
}

检查这个link获取更多信息

关于node.js - 带有偏移量和限制的嵌套包含 Sequelize,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41305088/

相关文章:

javascript - Node.js 请求数据事件未触发。我究竟做错了什么?

javascript - 在 JavaScript 中强制代码按顺序运行

node.js - Sequelize 从关系中获取模型对象

javascript - "Sequelize is not a constructor"初始化 Sequelize 时

node.js - Node.js 中 SERIAL 的外键违规

node.js - 为什么 node.js 不稳定?

javascript - NodeJS 需要模块导出中的函数吗?

mysql - 使用 Node + Express + Sequelize +(Mysql 或 Postgres)构建 SaaS 产品

javascript - 引用错误 : URL is not defined in Azure javascript function

sequelize.js - Sequelize js如何根据CURRENT_DATE进行日期比较