B
B
Bogdan2019-07-19 16:57:10
JavaScript
Bogdan, 2019-07-19 16:57:10

Sequelize bulkCreate returns incorrect value?

Hello. Don't tell me? I am using PostgreSQL database. I have a code field that is filled in by the before trigger automatically if null.
in Sequelize create() works as it should and returns a record, with code auto-filled

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 code with the value that we sent to the server (null), and not the one that was actually inserted.
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 }]

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question