I am trying to make an input form where the user can change several values in one row simultaneously which get submitted to the database using the update()
method. The values are being read from the Supabase Table into several input fields as defaultValues, which the user can edit and later submit form to update values in the Supabase instance of the table.
The input values received from user are stored in a object that has the shape :
inputFields = {
"name": "Piramal Glassed", // NEW
"email": "piramal@glass.com", // NEW
"contact": "98203" // NEW
"pin": 400066,
"city": "Mumbai",
"state": "Maharashtra",
"country": "India",
}
The values marked as // NEW
are the ones that have been changed by the user and need to be updated in the subsequent row in the Supabase Table.
I keep getting 400 Error. RLS is disabled for now. This is the function I am using to send the data back to the supabase table.
const { data, error } = await supabase
.from("company")
.update([inputFields.values])
.match([originalFields.values]); // Contains Original Values Of Row That Need To Be Replaced (same shape as inputFields.values)
};
What am I doing wrong here?
It looks like your match
filter doesn't work.
I would suggest trying to match row by its ID since you want to update only one row. This way you are actually trying to update all rows that match this data, and that might be causing an issue. I am not sure if we can batch update like this with supabase at the moment.
This is something I'm using in my apps whenever I want to update data for a single row, and I don't have any issues with it. I would suggest to try this, if the question is still relevant. 😊
await supabase.from("company").update(inputFields).match({ id: company.id });
or
await supabase.from("company").update(inputFields).eq("id", company.id)
You could also pass only new values to .update()
so you don't update whole row, but only data that has been changed.