Search code examples
supabasesupabase-databasesupabase-flutter

how to do nested queries in supabase for m2m relations


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?


Solution

  • 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)');