为了账号安全,请及时绑定邮箱和手机立即绑定

在 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 关注
  • 82 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信