The following code represents an Account Model in Sails.js v0.9.4 .
module.exports = {
attributes: {
email: {
type: 'email',
unique: true,
required: true
},
password:{
type: 'string',
minLength: 6,
maxLength: 15,
required:true
}
}
};
When I send two POSTS and a PUT request via Postman to localhost:8080/account, the unique property of the email fails. Specifically, I send the following HTTP requests from Postman:
POST http://localhost:8080/[email protected]&password=123456
POST http://localhost:8080/[email protected]&password=123456
PUT http://localhost:8080/account?id=1&[email protected]
GET http://localhost:8080/account
The last GET request shows me:
[
{
"email": "[email protected]",
"password": "123456",
"createdAt": "2013-09-30T18:33:00.415Z",
"updatedAt": "2013-09-30T18:34:35.349Z",
"id": 1
},
{
"email": "[email protected]",
"password": "123456",
"createdAt": "2013-09-30T18:33:44.402Z",
"updatedAt": "2013-09-30T18:33:44.402Z",
"id": 2
}
]
Should this happen?
*For those who don't know, Waterline generates by default an id which automatically increments in every insertion.
There is no need to delete current database to solve this, in stead change the waterline migrate
option from safe
to alter
. This way the underlying database will adapt this setting.
I wouldn't recommend migrate: alter
in a production environment, though. ;)
Here is my /config/local.js
:
module.exports = {
...
models: {
migrate: 'alter'
},
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With