Sorting by sequlize NVR m include order

model.Form.belongsToMany(model.Issue, { through: model.FormIssue,foreignKey:"formId",as:"formIssue"});


model.Issue.belongsToMany(model.Form,  { through: model.FormIssue,foreignKey:"issueId",as:"issueForm"});

model.FormIssue:

const FormIssue = app.model.define("fromIssue", {
        id: { type: INTEGER, primaryKey: true, autoIncrement: true },
        formId:{
            type:INTEGER,
            allowNull:false,
            comment:"Id"
        },
        issueId:{
            type:INTEGER,
            allowNull:false,
            comment:"Id"
        },
        createdAt: DATE,
        updatedAt: DATE,
        deletedAt : DATE,
      });

query:

let form=await ctx.model.Form.findOne({
              where:{id:formId},include:[
                  {
                      model:ctx.model.Issue,
                      as:"formIssue"
                  },

              ]
          });

there is no problem that the results can be found, and the list of formIssue questions queried by the question is not sorted according to the time of the formIssue table.
the query order is the same regardless of the chronological order of the operation.

I want the sequential sentence of the formIssue question list to be added to the createdAt sort of multiple pairs of tables, rather than according to the createdAt sort created by Issue itself

see on the Internet that order can be introduced into the model
so try:

let form=await ctx.model.Form.findOne({
              where:{id:formId},include:[
                  {
                      model:ctx.model.Issue,
                      order:[[model.FormIssue,"createdAt","DESC"]]
                      as:"formIssue"
                  },

              ]
          });

is still invalid in the end, could you tell me how to solve it?

Oct.20,2021

order can only take effect with the use of limit


try, it really takes limit,order to take effect, in include

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e45275-437cb.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e45275-437cb.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?