我试图在 Sequelize 中按列名排序
这是我的模型
var Milestones = sequelize.define('milestones', {
milestoneId: Sequelize.INTEGER,
data: Sequelize.JSON,
repository: Sequelize.STRING
});
数据库是 PostegreSql 9.5
var dialect = 'postgres',
protocol = 'postgres';
var sequelize = new Sequelize(dbConfig.database, dbConfig.user, dbConfig.password, {
host: dbConfig.host,
dialect: dialect,
protocol: protocol,
dialectOptions: {
timeout: 30
},
pool: {
max: 5,
min: 0,
idle: 30000,
maxConnections: 5,
maxIdleTime: 30
},
logging: false
});
这是我的查询
models.Milestones.findAll({
where: {
repository: req.body.repository
},
order: 'milestoneId'
}).then(function (values) {
// do something
});
这是我的错误
Unhandled rejection SequelizeDatabaseError: column "milestoneid" does not exist
所以问题是我想通过
milestoneId
订购,但 Sequelize 实际上试图通过 milestoneid
订购(注意缺少 Camel 案例)。如果我通过
repository
更改为 order 一切正常,那么此时的问题似乎与 Sequelize 转换为小写有关。除了将数据库中的列重命名为小写之外,还有什么建议吗?
谢谢
最佳答案
用一个字段更新你的模型就可以了
var Milestones = sequelize.define('milestones', {
milestoneId: {
type: Sequelize.INTEGER,
field: 'milestoneId'
},
data: Sequelize.JSON,
repository: Sequelize.STRING
});
编辑:
还更新订单
order: ['milestoneId']
关于javascript - 按列名顺序排列,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36015305/