使用 Node 和 Sequelize,是否可以定义一个模型,它使用驼峰命名法作为属性,但在转换为 json 时使用下划线/蛇形大小写?
现在;
var User = seq.define('user', {
id: {
type: Sequelize.INTEGER,
primaryKey: true
},
shortLivedToken: {
type: Sequelize.STRING,
field: 'short_lived_token'
},
longLivedToken: {
type: Sequelize.STRING,
field: 'long_lived_token'
}
}, {
underscored: true,
underscoredAll: true,
});
调用
response.json(user)
时变成{
"id": null,
"shortLivedToken": "abcde",
"longLivedToken": "fghji",
"updated_at": "2015-11-21T18:32:20.181Z",
"created_at": "2015-11-21T18:32:20.181Z"
}
我希望它是
{
"id": null,
"short_lived_token": "abcde",
"long_lived_token": "fghij",
"updated_at": "2015-11-21T18:32:20.181Z",
"created_at": "2015-11-21T18:32:20.181Z"
}
有任何想法吗?
最佳答案
https://github.com/sequelize/sequelize/issues/4906
关于json - 转换为 json 时续写下划线/蛇形大小写,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33847121/