Bulk upsert from table with Add Row and disabled primary key

Hello,

I have a mysql table that I display in a table component with columns ID and Name. The name is editable and the event handles for "save" is able to bulk upsert via primary key when I change a set records. However, I want to use the components feature to add new rows too. When I add a new row, the ID is not auto-incremented as I am using a table ( I've seen this is an options for forms apparently). In this case the Changeset Array is not complete and the bulk upsert does not work. How can I achieve both, updating and adding records form a table?
Thanks very much for any help!

2 Likes

Hi there @bastian and welcome to the forum!

There is a similar blog post here and another one with potential alternative solutions if the addrow doesn't work for you here.

In any case, the auto-incremented ID will not be added until you run the upsert query.

You can have two different actions in your save button, one conditioned to where newRows is not undefined/null that will insert the new record, one for changesetArray which will edit the changed records.

Hope this helps!