问题
I am using waterline v0.13.5 package with expressjs.
I get an user error
{ userError: The attribute 'str' on the 'action' model contains invalid properties. The property 'minLength' isn't a recognized property.
when trying to use min, max (with number type) and minLength, maxLength (with string type).This same type of error is also received with
isIn
property when used like this"isIn": [1,2,3]
.autoPK: true
also doesnt work as expected. It forces me to define _id in the model attributes definition and primaryKey key in the extend definition options.I am also not able to get the
types
validator function triggered in general. The functionisStringType
is not triggered when there is a entry into mongodb.
But the documentation for sails v1.0 says it can be done. This error is occuring when I am trying to extend/create the model using the Waterline.Collection.extend
function. I can specify manually the min and max but want to keep it dynamic for different attributes properties. So that is not a viable option.
waterline.registerModel(Waterline.Collection.extend({
identity: 'action',
datastore: 'recAuth',
schema: true,
tableName: 'action',
autoPK: true,
primaryKey: '_id',
types: {
isStringType: function (v) {
console.log('String validator triggered');
return typeof v === 'string';
}
},
attributes: {
"_id": {
"type": "string"
},
"str": {
"type": "string",
"required": true,
"minLength": 12,
"isStringType": true
}
}
}));
来源:https://stackoverflow.com/questions/53587393/sails-min-max-minlength-maxlength-for-number-and-string-types-gives-usererror