简体   繁体   English

排序bulkCreate返回不正确的值?

[英]Sequelize bulkCreate returns incorrect value?

And do not tell me? 而且不告诉我吗? I use the PostgreSQL base. 我使用PostgreSQL基础。 I have a field code which the trigger before is filled automatically if null. 我有一个域代码,如果为null,触发器之前的触发器将自动填充。 in sequelize create() works as it should and returns an entry with automatically inserted code. sequelize中的create()可以正常工作,并返回带有自动插入代码的条目。

const response = await models.Cartridge.create(
    { quantity, active, code: null },
    { returning: true }
  );

  // dataValues: {id: 5, quantity: 500, active: true, code: "090217205", updatedAt: Fri Jul 19 2019 16:35:59 GMT+0300 (Eastern European Summer Time), …}

and here, bulkCreate () returns a code with the value that we sent to the server (null), and not the fact that it was actually inserted. 在这里,bulkCreate()返回一个代码,该代码具有我们发送给服务器的值(空),而不是实际上已插入的事实。

const response = await models.Cartridge.bulkCreate(
    [{ quantity, active, code: null }],
    { returning: true }
  );

  // [ { dataValues: {id: 7, code: null, quantity: 500, active: true, createdAt: Fri Jul 19 2019 16:48:27 GMT+0300 (Eastern European Summer T }]

Can you try adding individualHooks. 您可以尝试添加单个挂钩吗? Downside is that will do single saves. 缺点是会节省一次。

const response = await models.Cartridge.bulkCreate(
[{ quantity, active, code: null }],
{ returning: true, individualHooks: true});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM