Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sequelize bulkCreate with updateOnDuplicate on all columns

I am using sequelize to perform a bulkCreate on one of my models. It is basically a simple sync-operation and therefore I want to update the rows that already exist. As per, the updateOnDuplicate is described as:

Fields to update if row key already exists (on duplicate key update)? (only supported by MySQL, MariaDB, SQLite >= 3.24.0 & Postgres >= 9.5). By default, all fields are updated.

However, there is no way to perform the default behavior. sequelize expects an array of strings and won't except e.g. a simple true for all columns.

So how can i update ALL fields?

like image 783
Fuzzyma Avatar asked Sep 05 '25 03:09

Fuzzyma


1 Answers

Something like this seems to work fine:

updateOnDuplicate: Object.keys(yourDataInstance)

like image 63
JKJ Avatar answered Sep 08 '25 00:09

JKJ