question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

New !inner join not working: "Could not find a relationship between trips and bookings in the schema cache"

See original GitHub issue

Bug report

Describe the bug

I follow the syntax explained here: https://postgrest.org/en/v9.0/api.html#embedding-with-top-level-filtering

I am attempting to utilize the new inner join functionality. I attempt to perform a simple query. If I leave out “!inner” it works well, however, with “!inner”, I get an error:

{
    "hint": "If a new foreign key between these entities was created in the database, try reloading the schema cache.",
    "message": "Could not find a relationship between trips and bookings in the schema cache"
}

Example:

  • Works = https://__.supabase.co/rest/v1/trips?select=bookings(id)
  • Does not works = https://__.supabase.co/rest/v1/trips?select=bookings!inner(id)

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  • Try similar queries as above

Expected behavior

I would expect, when not giving any filters to the query, to get the exact same response as if not including “!inner” in the query.

System information

  • Happens both using the Javascript SDK and through direct REST calls in Postman

Additional context

  • I have tried with multiple different relations in our setup. All of them behave the same.
  • I have attempted to restart our Supabase server in the cloud dashboard but that made zero difference.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
steve-chavezcommented, Dec 8, 2021

@mbalslow Yes, that’s intended behavior - does an INNER JOIN under the hood - it excludes top-level rows without an explicit filter(actually it contains an implicit filter, the ON clause of the INNER JOIN).

Maybe this is on purpose but it should be clearly clarified in the documentation

True. Actually on the PostgREST side we are thinking of adding an alternative way to specify this operation, which would enable doing:

GET /countries?select=name,cities(name)&cities=exists.true

Or through postgrest-js:

const { data, error } = await supabase
  .from('countries')
  .select(`
    *,
    cities (*)
  `)
  .exists('cities', true)

I think that would make the filtering more explicit.

2reactions
mbalslowcommented, Dec 1, 2021

@steve-chavez I can confirm that it now works so it was simply a matter of time until the instance was upgraded

Read more comments on GitHub >

github_iconTop Results From Across the Web

New !inner join not working: "Could not find a relationship ...
New !inner join not working: "Could not find a relationship between trips and bookings in the schema cache" #232.
Read more >
"Could not find a relationship" error : r/Supabase - Reddit
But I get this error: "Could not find a relationship between 'location' and 'facility_category' in the schema cache".
Read more >
How to fix error Base table or view not found - Stack Overflow
It seems Laravel is trying to use category_posts table (because of many-to-many relationship). But you don't have this table, because you've ...
Read more >
SQL JOIN TABLES: Working with Queries in SQL Server
The INNER JOIN query retrieves records from only those rows of both the tables in the JOIN query, where there is a match...
Read more >
Writing query results | BigQuery - Google Cloud
Access to the temporary table data is restricted to the user or service account that created the query job. You cannot share temporary...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found