bulkCreate with updateOnDuplicate updates the record (updatedAt) even if it is not changed #17247
Open
3 of 6 tasks
Labels
type: feature
For issues and PRs. For new features. Never breaking changes.
Issue Creation Checklist
Bug Description
I am using
bulkCreate
to create/update the records. If the records are already existing then they should get updated only if the required field has changed and also should automatically update the updatedAt timestamp.The issue I am facing is I have to provide the
updatedAt
field inupdateOnDuplicate
then only it updates the timestamp, and if I do so, then it updates the timestamp even if the required column is not changed, if I don't provide theupdatedAt
field in theupdateOnDuplicate
options then it only updates the required field and doesn't update the timestamp.Reproducible Example
Let's say that my table structure is:
Table Foo (a:int unique, b: string, createdAt: datetime, updatedAt: datetime)
and it has two records
if I use bulkCreate operation on table foo:
then it updates updatedAt for both records even when there was no change in second record (with b = 'two').
And if I use bulkCreate operation like the following
then it updates value of
b
for first record but doesn't update the timestampupdatedAt
for the first record.What do you expect to happen?
Ideally, the updatedAt timestamp should be handled by sequelize package, and it should update it only if there is any change in field
b
.What is actually happening?
Environment
Would you be willing to resolve this issue by submitting a Pull Request?
Indicate your interest in the resolution of this issue by adding the 👍 reaction. Comments such as "+1" will be removed.
The text was updated successfully, but these errors were encountered: