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:

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 });


And I thought that this would give me the user as { ...message, user }. But it's always returning
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
Was this page helpful?