How does one generate a query like this on mysql?
INSERT INTO t (t.a, t.b, t.c)
VALUES ('key1','key2','value'), ('key1','key3','value2')
ON DUPLICATE KEY UPDATE
t.c = VALUES(t.c)
On a single row, this is what upsert does, but it does not accept array of values. I have a use case where I need to either update or create multiple rows - I do not care for return values.
Solved using bulkCreate with updateOnDuplicate option.
In the documentation it states that by default all fields are updated, but that was not the case - ON DUPLICATE KEY UPDATE was not added. Had to set this property explicitly.
if you set updateOnDuplicate to a boolean value it will simply be ignored, that field should contain an array of fields, the code specifically checks for it to be an array, if not it does nothing
Solved using bulkCreate with
updateOnDuplicateoption.
In the documentation it states that by default all fields are updated, but that was not the case -ON DUPLICATE KEY UPDATEwas not added. Had to set this property explicitly.
updateOnDuplicate : [ ]
Most helpful comment
Solved using bulkCreate with
updateOnDuplicateoption.In the documentation it states that by default all fields are updated, but that was not the case -
ON DUPLICATE KEY UPDATEwas not added. Had to set this property explicitly.