回环2 - 定义一个模型
问题描述:
对象的数组,如果我有一个usermodel
和我定义:回环2 - 定义一个模型
"events": {
"type": [
"Object"
]
},
我需要定义什么在usermodel.js
别的能张贴的东西,如:[{name: 'sample', ...}, ...]
到用户表的事件列?
我问,因为如果我从.json
中删除这个特定的定义,应用程序编译和数据库迁移,但随着它,应用程序编译,但数据库状态有用户问题findByid
。我的调试已将其缩小到这组特定的代码。
答
另一种方法是定义你的数组作为一种模式在所需的对象,然后使用该模型作为你的类型:
型号:类
{
"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
},
}
}