Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(upsert): do not overwrite an explcit created_at during upsert (#1…
…3593) We found that when doing an upsert with model data that already included a `createdAt` timestampe, our explcit `createdAt` was being overwritten with the current time any time we also utilized the `fields` option. e.g. ``` const instance = await MyModel.upsert({ id: 1, myfield: 'blah', createdAt: new Date('2010-01-01T12:00:00.000Z') }, { fields: [ 'myfield' ], returning: true }); console.log(instance.createdAt); // expected 2010-01-01T12:00:00.000Z, but got a now()-ish timestamp. ``` Issue appears to be that the check for a provided `createdAt` was being checked against the `updateValues` instead of the `insertValues`. Most of the time, this is inconsequential because the `insertValues` and `updateValues` both contain the same fields. But, when using the `fields` feature, the `createdAt` field is stripped away from the `updateValues`, so sequelize happily overwrites the `insertValues.createAt` value. Co-authored-by: Sascha Depold <sdepold@users.noreply.github.com>
- Loading branch information