【发布时间】:2016-03-27 22:48:43
【问题描述】:
当我在数据库中创建新项目时,我试图为字段设置默认值,但我无法使其工作。
我目前使用的是 SailsJS 0.12.1,这是最新版本
这是我的文件的样子:
模型/Users.js
module.exports = {
schema: true,
attributes: {
firstName: {
type: 'string',
required: true,
},
role: {
type: 'string',
enum: ['admin', 'user', 'limited', 'suspended', 'deleted'],
defaultsTo: 'limited'
},
}
}
在数据库中创建元素时,我没有得到role 值。看起来是这样的:
{
"_id": {
"$oid": "56f8616163a59cf813998f8a"
},
"firstName": "Alex",
"createdAt": {
"$date": "2016-03-27T22:40:33.151Z"
},
"updatedAt": {
"$date": "2016-03-27T22:40:33.151Z"
}
}
知道我忘记了什么吗?
谢谢!
【问题讨论】:
-
尝试使用蓝图创建以进行测试.... localhst:PORT/users/create?firstName=XYZ 看看你得到了什么!
标签: javascript mongodb sails.js waterline