如果我有一个 usermodel
并且我定义:
"events": {
"type": [
"Object"
]
},
我是否需要在 usermodel.js
中定义任何其他内容才能发布如下内容:[{name: 'sample', ...}, ...]
到用户表的事件列?
我问是因为如果我从 .json
中删除此特定定义,则应用程序编译并且数据库迁移,但是使用它,应用程序编译但数据库指出用户存在问题findByid
。我的调试已将其范围缩小到这组特定的代码。
最佳答案
我认为你可以简单地使用这个结构
{
"events":{
"type": [
{
"key": "type",
"key2": "type"
}
]
}
}
您可以查看 .js 示例 here和 .json 示例 here . 但我也可以看到实现的问题 here那说
this model has problem. When we fetch the data with any get call, it renders this particular field as ["Object Object"] even though the data is properly saved in the database.
我建议您自行尝试,因为它在很大程度上取决于版本和驱动程序。
虽然我想问一下你用的是什么类型的数据库?
关于loopbackjs - loopback 2 - 在模型上定义对象数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45677849/