如何对数据进行排序Sequelize EmiratesToMany关联?

时间:2019-03-20 06:02:25

标签: node.js sequelize.js

我正在尝试使用Sequelize对以下架构的结果进行排序。但我遇到类似Unable to find a valid association for the model, 'UserProject'

的错误

请在下面找到我的代码,实际上,我想按UserProject.role

对结果进行排序
UserProject = sequelize.define('user_project', { role: Sequelize.STRING});
User.belongsToMany(Project, { through: UserProject });
User.findAll({
    include: {
      required: true,
      through: {
        attributes: [],
        model: UserProject
      },
      model:Project,
      order: [[{ model: UserProject}, "role", "ASC"]]
});

提前谢谢!

1 个答案:

答案 0 :(得分:0)

该怎么办?

User.findAll({
    include: {
      required: true,
      through: {
        attributes: [],
        model: UserProject
      },
      model:Project
    },
    order: [[UserProject, "role", "ASC"]]
});