我在模型中定义了一个唯一字段,但是当我尝试测试时,它似乎没有被sails 检查,因为我得到了Error (E_UNKNOWN) :: Encountered an unexpected error:
MongoError: E11000 duplicate key error index:
一个sails ValidationError。
处理帆中独特领域的最佳方法是什么?
// model/User.js
module.exports{
attributes: {
email: {required: true, unique: true, type: 'email' },
....
}
// in my controller
User.create({email: 'hello@gmail.com'}).then(...).fail(....)
User.create({email: 'hello@gmail.com'}).then(...).fail(// throws the mongo error )
// and same goes with update it throws error
提前谢谢各位。