回环2 - 定义一个模型

问题描述:

对象的数组,如果我有一个usermodel和我定义:回环2 - 定义一个模型

"events": { 
    "type": [ 
    "Object" 
    ] 
}, 

我需要定义什么在usermodel.js别的能张贴的东西,如:[{name: 'sample', ...}, ...]到用户表的事件列?

我问,因为如果我从.json中删除这个特定的定义,应用程序编译和数据库迁移,但随着它,应用程序编译,但数据库状态有用户问题findByid。我的调试已将其缩小到这组特定的代码。

我想你可以简单地使用这种结构

{ 
"events":{ 
    "type": [ 
     { 
      "key": "type", 
      "key2": "type" 
     } 
    ] 
} 
} 

你可以看到一个.js例如here和上传.json例如here。 但我也可以看到一个问题,执行here,说

这个模型有问题。当我们使用任何获取调用获取数据时,即使 数据正确保存在数据库中,它也会将此特定字段呈现为[“对象对象”]。

我建议你自己试试,因为它取决于版本和驱动程序。

虽然我想问你使用的是什么样的数据库?

另一种方法是定义你的数组作为一种模式在所需的对象,然后使用该模型作为你的类型:

型号:类

{ 
    "name": "Class", 
    "base": "Model", 
    "strict": true, 
    "idInjection": false, 
    "properties": { 
     "label": { 
      "type": "string", 
      "required": true 
     } 
    } 
} 

型号:学生

{ 
    "name": "Student", 
    "base": "PersistedModel", 
    "strict": true, 
    "idInjection": true, 
    "properties": { 
     "classes": { 
      "type": ["Class"], 
      "required": false 
     }, 
    } 
}