Querying Joins and Nested tables issue
I'm having an many-to-one issue on a query that I can't solve. Giving:
I need to reproduce the query below using supabase client syntax:
When I try this:
I get this error: i've added the error in the thread due to character limit.
Which is fine, but basically it is telling me to do something like this:
Which makes the query to work, but it's not what I want, because now it's relating
profiles_with_crew_owner_home_places.profile_id to profiles.created_by which is wrong. I need to relate profiles_with_crew_owner_home_places.profile_id with profiles.id. I've tried it in several ways but nothing works. Please tell me that It has a solution.7 Replies
Query error:
There is this tool: https://supabase.com/docs/guides/api/sql-to-rest
Basically the error shows you your choices for how to specify the relationship you want from the ones that exist between tables. Note they could be thru other tables also.
Thanks for the help, this tool is very helpful. Unfortunately the suggestion it gave throwed the same error.
You need to use one of the hints in your error to tell it which relationship to use. There is more than one between those tables.
the point is that none of the hints is what i want, i want to use profile's primary key as reference. Nevertheless i'm moving towards using raw sql for this. Gave up.
I just realized you are trying to use a view in this.
The API only relies on Foreign keys of the underlying tables. You can't do joins if there is not a table to table FK relation.
But sometimes it is better just to use an rpc to a table returning function as the REST API will not cover all cases.
I think that sucks because:
1. if
profiles didn't have the created_by and updated_by nested relations, the join would probably work.
2. I can do it easily with RAW SQL so it's clearly a PostgREST limitation.
Yeah, i'm going to do that. Thanks a lot man.