How to access the second level foreign key using Supabase

37 views Asked by At

I have countries tables and cities tables with a country field that refers to countries tables as a relation, and finally jobs table that has a city field that refers to the cities table .. now when I query on jobs. I can only access job.city and never being able to get job.city.country .. here is my code:


  async function fetchJobs() {
    const { data: fetchedJobs } = await supabaseInstance().from("jobs").select("*,cities!inner(*,countries!inner(id))").order('created_at', { ascending: false });
    setJobs(fetchedJobs)
  }

am pretty sure I have something wrong in the select query but I have been looking for the right one for ages and can't get it.

1

There are 1 answers

0
dshukertjr On

Assuming related cities and countries will always be present, you don't need !inner keyword.

    const { data: fetchedJobs } = await supabaseInstance().from("jobs").select("*,cities(*,countries(id))").order('created_at', { ascending: false });