Sailsjs/waterline specify number of decimal places in model

瘦欲@ 提交于 2019-12-04 14:52:48
Martin Malinda
  types: {
    decimal2: function(number){
      return ((number *100)%1 === 0);
    }
  },
  attributes: {
    myNumber: {
      type: 'float',
      decimal2: true
    }
  }

This is for 2 decimal places though. I cant find a way to make it for dynamically changing N as there is afaik no way to pass a parameter to custom validation. Workaround for this issue would be to check for custom amount of decimal places in beforeValidation() function.

I would not recommend (and I don't think its possible for float, maybe) adding a constraint in the model.

I'd suggest that you set:

migrate: "safe"

in your model and set the appropriate datatype/decimal Places in your tables.

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