how to do nested queries in supabase for m2m relations

88 views Asked by At

i have this structure in my database in supabase :

create table categories (
  "id" serial primary key,
  "name" text
);

create table jobs (
  "id" serial primary key,
  "job_title" text,
);

create table job_cat_rel (
  "job" int references jobs,
  "cat" int references categories,
  primary key (job, cat)
);

based on These docs from supabase I should simply call it in dart like this :

final data = await supabase.from('jobs').select('id, job_title, categories(id, name)');

but running this gives me a 400 error .. any help with that?

1

There are 1 answers

0
X8inez On BEST ANSWER

You would want to use !inner() join to retrieve nested values.

So you'll have something like this:

final data = await supabase.from('jobs').select('id, job_title, categories:categories!inner(id, name)');