如何在使用where和limit限制结果集的同时使用sequelize来检索嵌套内容?

时间:2018-06-23 20:13:16

标签: node.js sequelize.js feathersjs feathers-sequelize

在尝试使用限制和偏移量限制数据集时遇到问题。我可以成功获取数据而没有限制和偏移

context.params.sequelize = {
      raw: false,
      offset: parseInt(query.$skip),
      limit: parseInt(query.$limit),
      include: [{
        model: sequelize.models.class_fees,
        paranoid: true,
        distinct: true,
        where: {
          status: query.status
        },
        include:[{
          model: sequelize.models.classes,
          where: {
            id: query.classId
          },
          attribute:['name']
        }],
      },]
    };
    context.result=  await sequelize.models.student.findAndCountAll(context.params.sequelize);
    console.log(context.result);

我收到以下错误

  

信息:错误:学生-方法:查找:“ on子句”中的未知列“ class_fees.classId”   错误:SequelizeDatabaseError:“ on子句”中的未知列“ class_fees.classId”       在Query.formatError(D:\ Web \ ClassProject \ SahasIMS \ backend \ node_modules \ sequelize \ lib \ dialects \ mysql \ query.js:247:16)       在Query.handler上[作为onResult](D:\ Web \ ClassProject \ SahasIMS \ backend \ node_modules \ sequelize \ lib \ dialects \ mysql \ query.js:68:23)       在Query.Command.execute上(D:\ Web \ ClassProject \ SahasIMS \ backend \ node_modules \ mysql2 \ lib \ commands \ command.js:30:12)       在Connection.handlePacket(D:\ Web \ ClassProject \ SahasIMS \ backend \ node_modules \ mysql2 \ lib \ connection.js:502:28)       在PacketParser.onPacket上(D:\ Web \ ClassProject \ SahasIMS \ backend \ node_modules \ mysql2 \ lib \ connection.js:81:16)       在PacketParser.executeStart(D:\ Web \ ClassProject \ SahasIMS \ backend \ node_modules \ mysql2 \ lib \ packet_parser.js:77:14)       在套接字。 (D:\ Web \ ClassProject \ SahasIMS \ backend \ node_modules \ mysql2 \ lib \ connection.js:89:29)       在emitOne(events.js:96:13)       在Socket.emit(events.js:191:7)       在readAddChunk(_stream_visible.js:178:18)       在Socket.Readable.push(_stream_read.js:136:10)       在TCP.onread(net.js:561:20)

到目前为止,我可以通过添加subQuery: false来找到参数来找到解决方法,如果有人可以为此提供适当的解决方案,则表示高度赞赏。

0 个答案:

没有答案