Sailsjs模型中一定长度的字符串 [英] String of certain length in Sailsjs Model

查看:32
本文介绍了Sailsjs模型中一定长度的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何强制 Model 属性的长度恰好为 32 个字符?

How can I enforce a Model property to be exactly 32 characters long?

我试过了

key : {
    type: 'string',
    len : 32
}

但它不起作用.

推荐答案

好吧,让我告诉你我做了什么.

Ok, let me tell you what i did.

阅读数小时后,您会发现columnType"属性就是解决方案.它与type"属性一起使用.例如.我有一个描述"字段.它看起来像:

After reading hours y figure out that "columnType" property is the solution. It works together with "type" property. For example. I have a "description" field. It looks like:

描述:{类型:'字符串',columnType: 'varchar (27)' }

descripcion: { type: 'string', columnType: 'varchar (27)' }

它有效.(这是针对 mysql 数据库的).

And it works. (this is for mysql db).

我希望这对你有用.这是在文档上.模型逐字字段

I hope this works for you. This is on the docs. Model verbatim field

这篇关于Sailsjs模型中一定长度的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆