A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://stackoverflow.com/questions/79686134/how-to-add-order-clause-in-sequelize-cursor-pagination below:

node.js - How to add order clause in sequelize-cursor-pagination

I'm using the sequelize-cursor-pagination package to implement pagination in my Node-Postgres application. I need to order my results based on a field from an included (associated) model, but the package doesn't allow this.
NB: The order option format only supports the ['field'] and ['field', 'DESC'] variations (field name and the optional order direction). For example, ordering by an associated model's field won't work.

  const queryDict = {
    where: {
      orgPk,
    },
    include: [...(associations.includeControl ? [{ model: db.Control, as: 'control', where: { orgPk } }] : [])],
  }

I've attempted to add an order clause using Sequelize Literal

    order: associations.includeControl ? [[Sequelize.literal('CAST("control"."number" AS INTEGER)'), 'ASC']] : [],

But this works only for the first page, app crashes when second page is requested
errors: [ "message": "missing FROM-clause entry for table \"undefined\"",


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4