*Question regarding best practices for multiple co...
# help
j
Question regarding best practices for multiple column updates in a single row. Context: Say I have a
social
table that includes a row for each
user
. Within that row are columns for several social networks (twitter, youtube, twitch, whatever, etc.). Question: Chances are most users will not have every social network listed, but the form will include inputs for each social column available. That said, is there a specific way I should structure the update query? Or is it standard to submit all the fields and include fallback values with the existing state to catch those that are not in use/ okay as is? *Example: Is this standard/ okay? *
Copy code
const { data, error } = await supabase
  .from('social')
  .update(
    { twitter: newStateValue || prevStateValue},
    { youtube: newStateValue || prevStateValue}, 
    { twitch: newStateValue || prevStateValue}
  )
  .eq('user', user.id)
n
Hello @justinjunodev! This thread has been automatically created from your message in #843999948717555735 a ``few seconds ago``. Pinging @User so that they see this as well! Want to unsubscribe from this thread? Right-click the thread in Discord (or use the ... menu) and select Leave Thread to unsubscribe from future updates. Want to change the title? Use the
/title
command! We have solved your problem? Click the button below to archive it.
s
The syntax of your code would be wrong in that case as you are trying to update multiple rows rather than a row with multiple column. If all of these social networks are in one row then you only need to update the one that has changed without worrying about the previous state of the others.
n
justinjunodev (2022-03-11)