Open
Description
Improve documentation
In the documentation for fetching, under Query the same referenced table multiple times
, it states an approach, which doesn't infer correct types on the resulting object.
Link
https://supabase.com/docs/reference/javascript/select
Describe the problem
The documentation states this approach
const { data, error } = await supabase
.from('messages')
.select(`
content,
from:sender_id(name),
to:receiver_id(name)
`)
This works and fetches the correct data, but with typescript, the types are incorrect; from
and to
are both typed as {}[]
.
Describe the improvement
I believe the documentation should mention another possible approach, which is also mentioned in the PostgREST documentation, which returns the correct data and infers the types correctly:
const { data, error } = await supabase
.from('messages')
.select(`
content,
from:users!messages_from_fkey(name),
to:users!messages_from_fkey(name)
`)
Here the users
is the name of the foreign table from which we are querying and messages_from_fkey
and messages_from_fkey
are the names of the foreign key constraints.