【发布时间】:2013-10-06 17:56:56
【问题描述】:
以下代码表示 Sails.js v0.9.4 中的帐户模型。
module.exports = {
attributes: {
email: {
type: 'email',
unique: true,
required: true
},
password:{
type: 'string',
minLength: 6,
maxLength: 15,
required:true
}
}
};
当我通过Postman 向 localhost:8080/account 发送两个 POST 和一个 PUT 请求时,电子邮件的唯一属性失败。 具体来说,我从 Postman 发送以下 HTTP 请求:
POST http://localhost:8080/account?email=foo@gmail.com&password=123456
POST http://localhost:8080/account?email=bar@gmail.com&password=123456
PUT http://localhost:8080/account?id=1&email=bar@gmail.com
GET http://localhost:8080/account
最后一个 GET 请求显示我:
[
{
"email": "bar@gmail.com",
"password": "123456",
"createdAt": "2013-09-30T18:33:00.415Z",
"updatedAt": "2013-09-30T18:34:35.349Z",
"id": 1
},
{
"email": "bar@gmail.com",
"password": "123456",
"createdAt": "2013-09-30T18:33:44.402Z",
"updatedAt": "2013-09-30T18:33:44.402Z",
"id": 2
}
]
这应该发生吗?
*对于那些不知道的人,Waterline 默认会生成一个 id,它会在每次插入时自动递增。
【问题讨论】:
-
我可以通过设置
autoPK:false来克服这种“错误”行为。 -
当我将我的 autoPK 设置为 false 时,我的 id 列被删除了。
标签: node.js express sails.js waterline