Skip to content

Referencing missing column #930

@ohrrkan

Description

@ohrrkan

@supabase/supabase-js": "^2.39.0" using Supabase CLI to [generate the types] "supabase": "^1.123.0"

Query the same referenced table multiple times work but give you a Typescript error as it expect an array.

to reproduce you can use the datasource (doc example)

create table
 users (id int8 primary key, name text);

 create table
   messages (
     sender_id int8 not null references users,
     receiver_id int8 not null references users,
     content text
   );

 insert into
   users (id, name)
 values
   (1, 'Kiran'),
   (2, 'Evan');

 insert into
   messages (sender_id, receiver_id, content)
 values
   (1, 2, '👋');

query :

const { data, error } = await supabase
  .from('messages')
  .select(`
    content,
    sender_id(name),
    receiver_id(name)
  `)

now using data[0].sender_id.name will work but will give you an typescript error. "sender_id: SelectQueryError<"Referencing missing column name">[];

Bypass temporary solution :

type patch = { content: text; sender_id: Tables<"users">; receiver_id: Tables<"users">}[];

const { data, error } = await supabase
  .from('messages')
  .select(`
    content,
    sender_id(name),
    receiver_id(name)
  `).returns<patch>()

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions