Include "unselected" tags in changeset array

I have a many-to-many relationship between posts and tags in my postgres DB, and I want to be able to edit the tags from my Posts retool dashboard. I can't figure out how to determine when a tag has been unselected via the changeset array so that I can delete the rows, any suggestions?

1 Like

I also am trying to do this with checkboxes or toggles....

I reckon you need to compare the table source data against that changeset array to find out what's been removed and added. Assuming you're submitting on change:

// Pass the row index (selectedDataIndex) into the query via additionalScope
const existingTags =[rowIndex].tags
const updatedTags = table.changesetArray[0].tags

const deletedTags = existingTags.filter(x=> !updatedTags.includes(x))
const newTags = updatedTags.filter(x=> !existingTags.includes(x))

return {deletedTags: deletedTags, newTags: newTags}

Now you can pass those arrays to your DB query/queries.