这是表单模型架构:
{
"startTime": "",
"stopTime": "",
"id": "objectid",
"formQuestions": [
{
"type": 0,
"label": "",
"content": [
""
],
"id": "objectid"
}
]
}
form.json的关系:
"relations": {
"questions": {
"type": "embedsMany",
"model": "FormQuestion",
"option": {
"validate": true,
"autoId": true
}
}
}
如果我按照以下方式发布到http://localhost:3000/api/Forms,
{
"startTime": "",
"stopTime": "",
"formQuestions": [
{
"type": 0,
"label": "a label",
"content": ["the content"]
}
]
}
它返回:
{
"startTime": "",
"stopTime": "",
"id": "54ccf7ae6159f1bc0bc6b430",
"formQuestions": []
}
但是我想将嵌入式模型formQuestion也插入到数据库中,我该怎么做呢?如果有人能帮助我,我将不胜感激。
答案 0 :(得分:3)
没有人知道,但我找到了自己的方式。
这是因为有一些关于使用嵌入式文档生成自动id的错误。即使我将autoId
设置为true
,也没用。因此,如果我使用手动ID发布,它将会成功。
就像这样:
{
"startTime": "",
"stopTime": "",
"formQuestions": [
{
"id": 1,
"type": 0,
"label": "a label",
"content": ["the content"]
}
]
}