所以我在我們的 API 端點上使用 Node.js、Express.js 和 Sequelize。我們遇到了回應正文鍵被切斷的問題。
這是示例 GET 回應:
{
"error": false,
"data": [
{
"id": "3c6b9a8a-cbea-4daa-b0a1-22608d881837",
// health_appointment_assigned_to_user is a Foreign Key
"health_appointment_assigned_to_user": {
"user_id": "fb4a5104-fc9e-4f4f-96d8-5a5c9e2726e5",
"user_profiles": {
"user_profile_": "f0f90435-eebb-417f-b78d-d45e01f518a5",
"user_id": "fb4a5104-fc9e-4f4f-96d8-5a5c9e2726e5",
"first_name": "Josha",
"middle_name": "Galgo",
"last_name": "Galga",
"extension_nam": null,
"full_name": "Josha G. Galga",
"birth_date": "2022-09-14T00:00:00.000Z",
"gender": "Female",
"house_street": "data here",
"barangay": "data here",
"municipality": "data here",
"province": "data here",
"region": "data here",
"full_address": "data here",
"contact_numbe": "09211234567",
"image": "",
}
},
// health_appointment_assigned_to_physician is a Foreign Key
"health_appointment_assigned_to_physician": {
"user_id": "a5ad3552-6d19-4dd3-b6b9-8f93bab0739f",
"user_profiles": {
"user_pro": "027bfff1-a680-4dd7-a556-74916bf7ccaa",
"user_id": "a5ad3552-6d19-4dd3-b6b9-8f93bab0739f",
"first_na": "Melanie",
"middle_n": "Misoka",
"last_nam": "Martinez",
"extensio": null,
"full_nam": "Melanie M. Martinez",
"birth_da": "2001-01-21T00:00:00.000Z",
"gender": "data here",
"house_st": "data here",
"barangay": "data here",
"municipa": "data here",
"province": "data here",
"region": "NCR",
"full_add": "data here",
"contact_": "09211234567",
"image": "",
}
}
}
],
"message": "message here"
}
如您所見,回應主體鍵被無緣無故地切斷了。我們已經研究了模型,這里似乎沒有問題。然后,像“user_pro”這樣的鍵被切斷,原來是“user_profile_id”。
我也試過這個解決方案。但它似乎不適用于此解決方案。這里的任何見解將不勝感激!
uj5u.com熱心網友回復:
這是 Sequelize 中的常見問題。嘗試添加include: [{ separate: true, model: "Model name" }]
您的代碼。請注意,只有HasMany
關聯支持include.separate
.
參考:https ://github.com/sequelize/sequelize/issues/9684#issuecomment-1143442967
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/507657.html
上一篇:Express中間件ERR_HTTP_HEADERS_SENT中修改的ReqUrl:發送到客戶端后無法設定標頭
下一篇:無法從快遞中獲取資料做出反應