亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 Console.log 和 api 響應中獲取外鍵未定義

在 Console.log 和 api 響應中獲取外鍵未定義

白衣染霜花 2023-06-09 14:52:04
我有一個report_data屬于daily_entry表的表但是當我打電話api想要獲取daily_entry表的所有數據時它發送如下響應輸出{    "response_code": "0",    "message": "Operation is successfully executed",    "status": "success",    "data": {        "id": 1,        "user_id": 1,        "date": "12-10-2020",         other data ....        "is_active": true,        "createdAt": "2020-10-21T06:25:57.877Z",        "updatedAt": "2020-10-21T06:25:57.877Z",        "report_datum": {            "id": 1,            "entry_i": 1, <<<<<<<----------OUTPUT            "Date": null,            "report_document_id": "2",            "createdAt": "2020-10-21T06:26:02.642Z",            "updatedAt": "2020-10-21T06:26:02.642Z"        }    },    "level": "info",    "timestamp": "2020-10-21T06:25:45.947Z"}預期的{    "response_code": "0",    "message": "Operation is successfully executed",    "status": "success",    "data": {        "id": 1,        "user_id": 1,        "date": "12-10-2020",         other data ....        "is_active": true,        "createdAt": "2020-10-21T06:25:57.877Z",        "updatedAt": "2020-10-21T06:25:57.877Z",        "report_data": {            "id": 1,            "entry_id": 1,<<<<<-------------EXPECTED            "Date": null,            "report_document_id": "2",            "createdAt": "2020-10-21T06:26:02.642Z",            "updatedAt": "2020-10-21T06:26:02.642Z"        }    },    "level": "info",    "timestamp": "2020-10-21T06:25:45.947Z"}兩個表之間的關系是hasOnedb.daily_entry.hasOne(db.report_data, { onDelete: "cascade", foreignKey: 'entry_id', foreignKeyConstraint: true, targetKey: 'id' });我已經記錄了來自數據庫的數據,如下所示 dataValues:{id: 1, entry_i: 1, daily_entry : 8468476, date: 23-10-2020, …} get entry_id:? () {\n            return this.get(attribute);\n          } undefined我已經檢查了我的整個項目,沒有像這樣的名字entry_i
查看完整描述

1 回答

?
胡說叔叔

TA貢獻1804條經驗 獲得超8個贊

嘗試將表名更改為CamelCase,然后嘗試。


查看完整回答
反對 回復 2023-06-09
  • 1 回答
  • 0 關注
  • 135 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號