【问题标题】:Nested include with offset and limit Sequelize嵌套包含偏移和限制 Sequelize
【发布时间】:2017-06-07 23:05:40
【问题描述】:

是否有人在 Sequelize 中成功使用嵌套包含以及 Limit 和 Offset。我正在尝试使用 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}  

【问题讨论】:

标签: node.js sequelize.js


【解决方案1】:

你需要添加

子查询:假;

例如:

{
    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 以获取更多信息

【讨论】:

    猜你喜欢
    • 2019-02-05
    • 2017-08-27
    • 2021-02-09
    • 2021-05-01
    • 2017-06-22
    • 1970-01-01
    • 2019-04-11
    • 1970-01-01
    • 2021-08-05
    相关资源
    最近更新 更多