Reputation: 802
I'm using Sails and I have created a model, and most of its attributes are required, but if I post a JSON with most of its attributes missing it will still create the record in the db. I'm using sails-postgresql
.
I've even tried doing it manually with:
ModelName.create(req.body).done(function(){})
Upvotes: 2
Views: 2065
Reputation: 2122
You need to add a special fields to your models attributes - "required: true" or "minLength: 5"
module.exports = {
attributes: {
name: {
type: 'string',
maxLength: 20,
minLength: 5
},
email: {
type: 'email',
required: true
}
}
}
You can read about validation in sails models here - http://sailsjs.org/#!documentation/models
Upvotes: 3