4

OK , so I managed to get the default sort order going using this (thank you ) :

How Can I set the default Sort order in FeathersJs

this is pulling data from mssql

I added in an include in the hook to get related entities.

app.service("invoices").hooks({
  before(context) {
    const AssociatedModel = context.app.services.parcels.Model;
    context.params.sequelize = {
       include: [{ model: AssociatedModel }]
    };

    let { query = {} } = context.params;
    console.log(query)
    if (!query.$sort) {
      query.$sort = {
        id: -1
      };
    }
    context.params.query = query;
  }
});

The end of the SQL statement generated

ORDER BY [Invoice].[id] DESC, [Invoice].[id] OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY;

and I get the error;

"A column has been specified more than once in the order by list. Columns in the order by list must be unique."

before I put the related entities in , it worked fine - but this breaks. Maybe it relates to something like this old bug..? Sequelize mssql: order by primary key and limit

Or maybe I am implementing this incorrectly.

Martin Thompson
  • 3,415
  • 10
  • 38
  • 62

0 Answers0