https://supabase.com/ logo
Hey everyone. I am currently trying to perform so...
# help
e
Hey everyone. I am currently trying to perform some logic on the following tables...
reports
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...
Copy code
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.
n
Hello @Ethanxyz! This thread has been automatically created from your message in #843999948717555735 a few seconds ago. We have already mentioned the @User so that they can see your message and help you as soon as possible! 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.
e
PS: Deleting the rows from Supabase UI works without having to go to the
reports
table and remove the FK
I am thinking that maybe Supabase UI has different methods for deleting, ignoring this error.
n
1. I believe you can change the relation constraint. I don't know the exact command but it's like
onDelete
or
onUpdate
. You can set it to onCascade or NoAction(which I think you want)
2. Is one bonds connected to one report or is it a Many to Many relationship?
g
2) You should be able to use .in('bond_id', selectedBonds) to match all array items.
e
I have
bonds
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.
I will look into this. I did not see any options in the Supabase UI to do this