Sails min, max, minLength, maxLength for number and string types gives userError

可紊 提交于 2020-01-05 09:28:00

问题


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 function isStringType 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!