© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•14mo ago•
6 replies
AndyJessop

Could not find a relationship between 'messages' and 'user' in the schema cache

I'm using the js client to try to attach a "user" to each "message". You can see from the attached screenshot that I have the user id setup as a fk. I believe this is all correct.

I have two RLS policies on
messages
messages
:

alter policy "Enable all actions for authenticated users only"
on "public"."messages"
to authenticated
using (
  true
with check (
  true
);

alter policy "check either user or agent is not null"
on "public"."messages"
to public
using (
  ((author_user_uuid IS NOT NULL) OR (author_agent_uuid IS NOT NULL))
with check (
  ((author_user_uuid IS NOT NULL) OR (author_agent_uuid IS NOT NULL))
);
alter policy "Enable all actions for authenticated users only"
on "public"."messages"
to authenticated
using (
  true
with check (
  true
);

alter policy "check either user or agent is not null"
on "public"."messages"
to public
using (
  ((author_user_uuid IS NOT NULL) OR (author_agent_uuid IS NOT NULL))
with check (
  ((author_user_uuid IS NOT NULL) OR (author_agent_uuid IS NOT NULL))
);


I don't have any user table policies because those are locked (by design I think?)

Now, I'm getting the data like this

const { data, error } = await this.#client
    .from("messages")
    .select(`
        *,
        agent:author_agent_uuid(uuid, display_name),
        user(id, email)
    `)
    .eq("channel_uuid", channelId)
    .order("created_at", { ascending: true });
const { data, error } = await this.#client
    .from("messages")
    .select(`
        *,
        agent:author_agent_uuid(uuid, display_name),
        user(id, email)
    `)
    .eq("channel_uuid", channelId)
    .order("created_at", { ascending: true });


And I thought that this would give me the user as
{ ...message, user }
{ ...message, user }
. But it's always returning
null
null
. The messages have all been created with a valid user.

How can I debug this further?
Screenshot_2025-01-06_at_18.55.02.png
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Could not find a relationship in the schema cache
SupabaseSSupabase / help-and-questions
13mo ago
Could not find a relationship between 'ev_opportunities' and 'sportsbooks' in the schema cache
SupabaseSSupabase / help-and-questions
3mo ago
Could not find a relationship between 'lists' and 'creator'
SupabaseSSupabase / help-and-questions
4y ago
Could not find a relationship between 'products' and 'prices'
SupabaseSSupabase / help-and-questions
4y ago