SailsJS - How to specify string attribute length without getting error when creating record?

后端 未结 2 964
陌清茗
陌清茗 2021-01-06 01:08

I\'m using Sails 0.9.8 paired with MySQL and wanting to do something like this

localhost:1337/player/view/

instea

相关标签:
2条回答
  • 2021-01-06 01:27

    The marked answer is quiet old. As per the latest sails version (1.0.2 as of the date of writing this answer),

    I used the columnType attribute like this:

    attributes: {
    
      longDescription: {
        type: 'string',
        columnType: 'text'
      }
    }
    
    0 讨论(0)
  • 2021-01-06 01:36

    You could work around this by defining custom validation rules via the types object. Specifically the given problem could be solved by defining a custom size validator that always returns true.

    // api/models/player.js
    module.exports = {
      types: {
        size: function() {
           return true;
        }
      },
    
      attributes: {
        username: {
          type: 'string',
          unique: true,
          minLength: 4,
          maxLength: 32,
          size: 32,
          required: true
        }
      }
    }
    
    0 讨论(0)
提交回复
热议问题