Lukas V
07/19/2022, 7:36 PMzavbala
07/19/2022, 8:25 PMjar
07/19/2022, 11:02 PMSajeev
07/20/2022, 2:24 AMEthanxyz
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.Sajeev
07/20/2022, 3:15 AMAlanK
07/20/2022, 6:14 AMexport const GET = async ({ locals, request }) =>
withApiAuth(
{
user: locals.user
},
async () => {
const { data: profile, error } = await supabaseServerClient(request)
.from('profile')
.select('*')
.eq('id', locals.user.id);
if (error) {
console.log('error Get Profile for Survey:', error);
return {
status: 400,
body: { error }
};
return {
status: 200,
body: { surveyData }
};
}
return {
status: 400,
body: {}
};
}
);
azel
07/20/2022, 8:50 AMSiddharth
07/20/2022, 9:02 AMPeteVanF
07/20/2022, 9:37 AMKalo0m
07/20/2022, 10:51 AMAmberon
07/20/2022, 11:11 AMJude
07/20/2022, 1:10 PMtitle
bookmarks: []
Where I'll reference the Bookmark tablevMInvincible
07/20/2022, 2:01 PMKevin Mann
07/20/2022, 2:04 PMconst { data, error } = await supabase.from("schema.table").select();
React noob
07/20/2022, 3:53 PMTater Of Tots
07/20/2022, 6:38 PMstudents
table and then the function also gets an array of phone numbers and I need to add them to the phones
table with the new student_id
. I have gotten far enough that it add the student and returns the id then puts the id in a variable. The part I'm stuck on is the syntax for taking this array of phone numbers and and adding a row for each number along with the student_id
. Heres what I have so far
create or replace function insert_student(
first_name text,
last_name text,
grade text,
dob date,
phones phone_type[]
)
RETURNS setof students
AS $$
declare
student_id int8;
begin
INSERT INTO students
(first_name, last_name, grade, dob) values (first_name, last_name, grade, dob)
returning id INTO student_id;
INSERT INTO phones
(phone_number, student_id) values
(phones, student_id); --THIS IS THE PART I'M STUCK ON
RETURN query select * from students where students.id = student_id;
end;
$$ language plpgsql;
React noob
07/20/2022, 7:32 PMzavbala
07/20/2022, 9:02 PMReact noob
07/20/2022, 11:23 PMjs
image_url: [dataKey]
because error say "details": "Array value must start with \"{\" or dimension information." and i do don't get itKolby
07/21/2022, 1:40 AMquangtd.near
07/21/2022, 2:44 AMjar
07/21/2022, 4:54 AMdeclare
_person_id uuid;
begin
select id from public.persons where user_id = auth.uid()::text into _person_id;
select 1 from public.person_roles where person_id = _person_id and role_id = 'admin';
end;
This is my not correct but gives idea of aimNeedle
07/21/2022, 5:57 AMInASunshineState
07/21/2022, 6:41 AMzenny.eth
07/21/2022, 7:25 AMChiqui
07/21/2022, 10:50 AMderpwingduk
07/21/2022, 12:20 PMRubensNobre
07/21/2022, 12:47 PMReact noob
07/21/2022, 12:59 PMsql
create policy insert_as_admin ON storage.buckets.id = 'hiking-picture'::text for all using (
(EXISTS ( SELECT 1
FROM profiles
WHERE ((profiles.admin IS TRUE) AND (profiles.id = 'b815-8e02-6c3f13e05026'::uuid))))
);
I have a syntax error ``Failed to validate sql query: syntax error at or near "="`` but i don't really see where it at