I'm trying to use the supabase-js package (with next js) to query data in my supabase postgres DB. I have set up 2 tables. One (users) with a foreign key referencing another (organisations). I've tried querying the data in the following ways:
const { data, error } = await supabase.from('users').select(`
*,
organisations (
*
)
`);
// or
const { data, error } = await supabase.from('users').select('*, organisations(*)');
The supabase object above is created using createServerComponentClient from @supabase/auth-helpers-nextjs.
But I always get null back for data.organisations and for error. The rest of the user data is there.
Also, if I query the data directly using an SQL join (... JOIN organisations ON users.organisation_id = organisations.id) I am able to fetch the organisation, so I know that the foreign key reference is working in the database. Can someone tell me what I'm doing wrong?
"next": "13.4.19",
"@supabase/supabase-js": "^2.37.0",
"@supabase/auth-helpers-nextjs": "^0.8.1"
@supabase/supabase-jswith it in order to get the fullness of the framework. You need to use the@supabase/auth-helpers-nextjs, going through the getting started here will get you up to speed with the auth-helpers and nextjs supabase.com/docs/guides/getting-started/tutorials/with-nextjsauth-helpers-nextjspackage, but that in turn is using thesupabase-jspackage. I should have made that more clear. I'm usingcreateServerComponentClientfrom@supabase/auth-helpers-nextjs(version: ^0.8.1) to create the client that I am using the code in the original question.