0

i have the following models :

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();
  }
};

and i have the following code :

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

and raise an error

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

How to sort by idx which idx is field of model Appmodule?

1 Answers1

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

As Your error is informing that you mentioned bad field name. Here you have idx field in Appmodule and you are querying in Appgroupmodule so that's why adapter is throwing this error.

Now You require to sort based on appmodule.idx so your argument should be like this

Appgroupmodule.find({appgroup_id:req.session.user.appgroup_id,active:0})
.populateAll()
.sort({'appmodule_id':{'idx':'asc'}})
Satyam Koyani
  • 4,236
  • 2
  • 22
  • 48