首页 > 解决方案 > 在 SailsJS 1.0 模型中定义一个数组

问题描述

我们一直在 SailsJS 0.12 上运行应用程序 - 一旦 1.0 发布,就会运行升级过程并升级

以前,一些模型支持“数组”类型,现在不再支持。有什么替代方法?它不在示例应用程序或文档中

我的模型是:

module.exports = {
attributes: {
    provider: 'string',
    uid: 'string',
    email: 'string',
    name: 'string',
    firstName: 'string',
    lastName: 'string',    
    password: 'string',    
    projects: {
      collection: 'project',
      via: 'owner'
    },
    creditsHistory:{
      collection: 'creditsHistory',
      via: 'owner'
    },    
    userRoles: {type: 'array', defaultsTo : [roles.USER]}
  },

Sails 1.0 中支持的类型是:https ://sailsjs.com/documentation/concepts/models-and-orm/attributes

没有任何关于用sails 0.12支持的类型替换数组类型的示例或示例: https ://0.12.sailsjs.com/documentation/concepts/models-and-orm/attributes

有人对此有任何想法吗?

标签: sails.jswaterline

解决方案


你可以这样使用它:

'coordinate': {
      'type': 'json',
      'required': true,
    },

或者你可以像这样使用它:

'cost_price': {
      'type': 'ref',
      'columnType': "double"

    },

colunmType您可以定义数据库列类型


推荐阅读