Open
Description
Package version
21.6.1
Describe the bug
Description:
When using updateOrCreateMany() with predicates that include a date field, the method throws an ER_DUP_ENTRY SQL error if a matching row already exists. Instead of updating the existing row, it attempts to insert a duplicate, which violates the unique constraint.
Expected Behavior:
If a row matches the provided predicate, updateOrCreateMany() should update the existing row, not attempt to insert a new one.
Actual Behavior:
A duplicate entry error is thrown (ER_DUP_ENTRY) when the method encounters a row that already exists for the given predicate, including a date field.
Example code:
await MyModel.updateOrCreateMany(['someId', 'date'], [
{ someId: 1, date: '2024-01-01', status: 'confirmed' },
{ someId: 1, date: '2024-01-02', status: 'pending' },
{ someId: 2, date: '2024-01-02', status: 'pending' },
])
ER_DUP_ENTRY: Duplicate entry '1-2024-01-01' for key 'my_model_some_id_date_unique'
Reproduction repo
No response
Metadata
Metadata
Assignees
Labels
No labels