Sequelize – 按降序获取值

我使用sequelize连接到mysql数据库。 我有2个表ApplicationVersion和提供者在我的数据库。 两个表都是关联的。 ApplicationVersion将Provider'uuid'作为外键。

在我的提供程序表中,我有一个名为weight的列。 这个权重字段有整数值。 我想以降序显示元素。 所以我已经在我的函数中使用了这一行order: [Sequelize.col('weight'), 'DESC'],但它不起作用。 如果我从它删除命令,该function运作良好。

这个function:

 function getactiveProvidersList(user, callback) { Provider.findAll({where: {enabled: 1}, include: [{ model: ApplicationVersion, where: {'active': true}, }], order: [Sequelize.col('weight'), 'DESC'], }).then(function(providers) { callback(providers); }); } 

你能告诉我这样做的正确方法,也是我搞砸了。

任何build议是有帮助的。 谢谢!

尝试这个。

 function getactiveProvidersList(user, callback) { Provider.findAll({where: {enabled: 1}, include: [{ model: ApplicationVersion, where: {'active': true}, }], order: ['weight','DESC'], }).then(function(providers) { callback(providers); }); } 

这里也有更多关于这个页面底部的build议

http://docs.sequelizejs.com/manual/tutorial/querying.html