Ethanxyz
07/20/2022, 3:02 AMreports
bonds
report_bonds
report_bonds is a junction for reports and bonds and looks like....
id
report_id ( FK )
bond_id (FK)
This allows me to create reports which hold a list of bonds.
On my Reports.js page I want to delete some of the bonds from a report. To do this, I am doing something like...
js
const removeBondFromReport = async () => {
const { data, error } = await supabase.from("report_bonds").delete().match({
bond_id: selectedBonds[0],
report_id: report.id
});
if (error) {
alert(error.message);
console.log(error.message);
}
};
Issues....
1. I get an error for FK restraint on my reports table, This is because the reports table has a FK for report_bonds id.
2. Notice how I say bond_id: selectedBonds[0], in my query ? Well, selected bonds is an array ( I have this connected to a MUI data grid which allows me to select rows and add them to an array )
Questions....
1. How can I solve #1
2. Is there a way to perform this query using the whole`selectedBonds` array (e.g. deleting multiple rows at once ) ?
Thank you for taking the time to read.Needle
07/20/2022, 3:02 AMEthanxyz
07/20/2022, 3:05 AMreports table and remove the FKEthanxyz
07/20/2022, 3:06 AMNanoBit
07/20/2022, 4:19 AMonDelete or onUpdate. You can set it to onCascade or NoAction(which I think you want)NanoBit
07/20/2022, 4:20 AMgaryaustin
07/20/2022, 2:32 PMEthanxyz
07/23/2022, 2:41 AMbonds and reports table, and then another tabled called report_bonds which looks like..
- id
- report_id ( FK )
- bond_id ( FK )
This was my way of getting around using an arr[] to store all the bonds.Ethanxyz
07/23/2022, 2:41 AM