Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 续集插入级联_Mysql_Node.js_Sequelize.js - Fatal编程技术网

Mysql 续集插入级联

Mysql 续集插入级联,mysql,node.js,sequelize.js,Mysql,Node.js,Sequelize.js,我正在尝试在多个表中插入 让我解释一下,用户创建一个新的客户机,客户机将id插入bill-(idClient)表 这是有效载荷 { "name": "Evelyn", "lastName": "Doe", "phone": "4534534", "email": "eve@hotmail.com", "ide

我正在尝试在多个表中插入

让我解释一下,用户创建一个新的客户机,客户机将id插入bill-(idClient)表

这是有效载荷

{
  "name": "Evelyn",
  "lastName": "Doe",
  "phone": "4534534",
  "email": "eve@hotmail.com",
  "identification": "xxxxx",
  "services": [1, 2, 3],
  "bill":{
    "description": "New project"
  }
}
{
  "name": "Evelyn",
  "lastName": "Doe",
  "phone": "4534534",
  "email": "eve@hotmail.com",
  "identification": "xxxxx",
  "description": "new Proyect",
}
插页

_service.create = async (client) => {
 const { description } = client.bill;
 try {
   const data = await Client.create(
    { client, bill: { description: description } },
    { include: { model: Bill } }
   );
  return data.id;
} catch (err) {
    handleError = err.hasOwnProperty("errors")
      ? err.errors.map((error) => error.message)
      : err;
    throw new Error(handleError);
  }
};
但是我得到了这个错误

{
 "name": "Error",
 "message": "ReferenceError: description is not defined"
}
是的,bill表有那个列

关系

Client.hasOne(models.Bill, { foreignKey: "idClient" });
所以,我被卡住了,我阅读了文档,我试图用和他们一样的方式去做,但我不知道我做错了什么


我已经做了,我不知道最好的方法是什么

我修改了有效载荷

{
  "name": "Evelyn",
  "lastName": "Doe",
  "phone": "4534534",
  "email": "eve@hotmail.com",
  "identification": "xxxxx",
  "services": [1, 2, 3],
  "bill":{
    "description": "New project"
  }
}
{
  "name": "Evelyn",
  "lastName": "Doe",
  "phone": "4534534",
  "email": "eve@hotmail.com",
  "identification": "xxxxx",
  "description": "new Proyect",
}
在插入查询中,将bill更改为bill作为我的表名,然后添加说明值

const { description } = client;
const data = await Client.create(
  { ...client, Bill: { description } },
  { include: { model: Bill } }
);
结果呢

{
"id": 6,
"name": "Evelyn",
"lastName": "Doe",
"phone": "4534534",
"email": "eve@hotmail.com",
"identification": "xxxxx",
"idStatus": 2,
"createdAt": "2020-11-13T08:52:37.000Z",
"updatedAt": "2020-11-13T08:52:37.000Z",
"Bill": {
  "id": 4,
  "idClient": 6,
  "totalAmount": null,
  "description": "new Proyect",
  "idStatus": 2,
  "createdAt": "2020-11-13T08:52:37.000Z",
  "updatedAt": "2020-11-13T08:52:37.000Z"
  }
}

我不知道你从哪里得到的
description
variable。是啊,妈,很糟糕,我错过了