How to investigate "No relationship between table1 and table2" error #258
-
I think I've created my relationships correctly with foreign keys and references but my supabase client request fails with
It used to work but I must have changed something. How do I investigate this further? It would be REALLY nice to have a way in the UI to see the configured relationships, potential issues, possible resolutions, and hints for adding/removing relationships. |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments
-
Hey @richcorbs - let us know the project ID and we'll see what we can do. Sometimes it requires a PostgREST restart to detect the relationships. This is automated, so it's strange that it's not picking up yours - it suggests that PostgREST didn't restart when you changed your schema.
We're working on better support for this now, trying to make it as easy as possible for developers to solve issues directly in the dashboard |
Beta Was this translation helpful? Give feedback.
-
I think the id is This is the query that fails:
|
Beta Was this translation helpful? Give feedback.
-
Hi @richcorbs. Looks like you have two relationships between If you do: supabase.from('events').select("*,event_teams(*,teams(*)),races(*,registrations(*),finishers(*))") Then you'll get the error: {
"hint": "By following the details key, disambiguate the request by changing the url to /origin?select=relationship(*) or /origin?select=target!relationship(*)",
"details": [
{
"relationship": "fk_race[id][race_id]",
"origin": "public.races",
"cardinality": "o2m",
"target": "public.registrations"
},
{
"relationship": "public.finishers[fk_race][fk_registration]",
"origin": "public.races",
"cardinality": "m2m",
"target": "public.registrations"
}
],
"message": "More than one relationship was found for races and registrations"
} (Here o2m is one-to-many and m2m is many-to-many) For clearing the error, you can choose between these two requests: supabase.from('events').select("*,event_teams(*,teams(*)),races(*,registrations!fk_race(*),finishers(*))")
//or
supabase.from('events').select("*,event_teams(*,teams(*)),races(*,registrations!finishers(*),finishers(*))") Note that Hope that helps! More details about this can be found on PostgREST Embedding Disambiguation docs. |
Beta Was this translation helpful? Give feedback.
-
How can you tell that I have two relationships between races and registrations? I only want a race to have many registrations (via registrations.race_id). |
Beta Was this translation helpful? Give feedback.
-
I should also say "thank you"! The I only remember moving an fk constraint from a table and that query was working prior to removing the fk constraint. Where is the second relationship coming from? Is it races -> finishers -> registration? How can I avoid that? What I want ultimately is:
|
Beta Was this translation helpful? Give feedback.
-
Great! If it makes things more clear, you can also use the fk column(race_id) instead of the fk name: supabase.from('events').select("*,event_teams(*,teams(*)),races(*,registrations!race_id(*),finishers(*))")
We look at the foreign keys and possible junction tables for finding the relationships.
In this case, since
Right now we auto-generate the relationships by introspecting your schema, but we'll be looking at how to make them customizable. For now, the hint( |
Beta Was this translation helpful? Give feedback.
Hi @richcorbs.
Looks like you have two relationships between
races
andregistrations
- a one-to-many and a many-to-many. In these cases, you need to disambiguate the request for getting your desired response.If you do:
Then you'll get the error: