填充后如何排序?

时间:2015-03-19 16:10:01

标签: sails.js waterline

我有以下型号:

Appgroupmodule.js

module.exports = {
  autoPK: false,
  freezeTableName: true,
  autoCreatedAt: false,
  autoUpdatedAt: false,
  attributes: {
    appgroup_id:{
      model: 'Appgroup'
    },
    appmodule_id:{
      model: 'Appmodule',
      primaryKey: true
    },
    active: 'INTEGER'

  }
};

Appmodule.js

var uuid = require('node-uuid');

module.exports = {
  autoPK: false,
  freezeTableName: true,
  autoCreatedAt: false,
  autoUpdatedAt: false,
  attributes: {
    id: {
        type : 'uuidv4',
        primaryKey: true,
        required: true
    },
    name: 'STRING',
    url: 'STRING',
    idx: 'INTEGER',
    flag: 'INTEGER',
    deleted: 'INTEGER',
    uplink: 'STRING'

  },
  newid: function(){
    return uuid.v4();
  },
  beforeCreate: function(values,next){
    values.id = uuid.v4();
    next();
  }
};

我有以下代码:

Appgroupmodule.find({appgroup_id:req.session.user.appgroup_id,active:0})
.populateAll()
.sort({'idx':'asc'})

并引发错误

  

详细信息:错误:ER_BAD_FIELD_ERROR:未知列   'order clause'中的'appgroupmodule.idx'

如何按idx排序哪个idx是模型Appmodule的字段?

1 个答案:

答案 0 :(得分:1)

Details: Error: ER_BAD_FIELD_ERROR: Unknown column 'appgroupmodule.idx' in 'order clause'

由于您的错误通知您提到了错误的字段名称。您在Appmodule中有 idx 字段,并且您在Appgroupmodule中查询,这就是适配器抛出此错误的原因。

现在你需要根据appmodule.idx进行排序,这样你的论点应该是这样的

Appgroupmodule.find({appgroup_id:req.session.user.appgroup_id,active:0})
.populateAll()
.sort({'appmodule_id':{'idx':'asc'}})