LoopBackJs REST API 创建响应不返回完整模型,仅返回表单数据
LoopBackJs REST API Create response not returning full model, only form data
当我 POST 到 api/testmodel 使用仅包含必填字段的对象时,该对象正在数据库中正确创建。但是,我只得到我在请求正文中发送的对象。我正在尝试在响应中获取包含空字段的完整对象。
感谢您的帮助!
{
"name": "test",
"plural": "test",
"base": "PersistedModel",
"idInjection": true,
"replaceOnPUT": false,
"properties": {
"city": {
"type": "string",
"length": 100
},
"name": {
"type": "string",
"required": true,
"length": 100
},
"id": {
"type": "string",
"id": true,
"required": true,
},
"officePhone": {
"type": "string",
"length": 100
},
"status": {
"type": "string",
"required": false,
"length": 200
},
"street": {
"type": "string",
"length": 100
}
},
"methods": {}`
然后您需要为模型创建默认值,例如城市:
"properties": {
"city": {
"type": "string",
"length": 100,
"default": ""
},
...
在您的控制器中,在您创建新记录并获得记录 ID 后,执行 findById
查询并 return 该对象而不是 return 从 create
。这应该会给你一个类似于 GET 路由的响应。
当我 POST 到 api/testmodel 使用仅包含必填字段的对象时,该对象正在数据库中正确创建。但是,我只得到我在请求正文中发送的对象。我正在尝试在响应中获取包含空字段的完整对象。
感谢您的帮助!
{
"name": "test",
"plural": "test",
"base": "PersistedModel",
"idInjection": true,
"replaceOnPUT": false,
"properties": {
"city": {
"type": "string",
"length": 100
},
"name": {
"type": "string",
"required": true,
"length": 100
},
"id": {
"type": "string",
"id": true,
"required": true,
},
"officePhone": {
"type": "string",
"length": 100
},
"status": {
"type": "string",
"required": false,
"length": 200
},
"street": {
"type": "string",
"length": 100
}
},
"methods": {}`
然后您需要为模型创建默认值,例如城市:
"properties": {
"city": {
"type": "string",
"length": 100,
"default": ""
},
...
在您的控制器中,在您创建新记录并获得记录 ID 后,执行 findById
查询并 return 该对象而不是 return 从 create
。这应该会给你一个类似于 GET 路由的响应。