Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Referencing missing column #930

Closed
ohrrkan opened this issue Dec 20, 2023 · 19 comments
Closed

Referencing missing column #930

ohrrkan opened this issue Dec 20, 2023 · 19 comments
Labels
bug Something isn't working

Comments

@ohrrkan
Copy link

ohrrkan commented Dec 20, 2023

@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>()
@ohrrkan ohrrkan added the bug Something isn't working label Dec 20, 2023
@dvsmc
Copy link

dvsmc commented Feb 13, 2024

Is there any PR which fixes those? I recently updated supabase-js version and generated new types and got similar issue, some database fields are not recognized anymore. I cant pinpoint the exact moment it stated to break tho.

Edit: For me this solved it - #974

@nabilhayek
Copy link

Same problem for me even when switching to 2.39.3
image

@RiodeJaneiroo
Copy link

i got the same error

@AndrianMauricio
Copy link

Same here!

@yaberkane05
Copy link

same here...

@rnnc
Copy link

rnnc commented Jul 18, 2024

still an issue

@artilishes
Copy link

Same here. Weirdly, this works...

supabase
  .from('selection_assets')
  .select(
    `
    id,
    comment,
    order,
    created_at,
    asset: assets (
      id,
      name,
      is_listed
    )
  `,
  )
  .eq('selection_id', selectionId)
  .single();

and this doesn't...

supabase
  .from('selections')
  .select(
    `
    *,
      client: client_id(id)
    `,
  )
  .eq('id', selectionId)
  .single();

@theshadowagent
Copy link

still an issue

@Th1nhNg0
Copy link

Got the issue too

@MattieTK
Copy link

Same issue

@silvaMatheus
Copy link

Any solution?

@karladler
Copy link

I have the feeling it depends on in which direction or on which side the relation is defined. Still need to verify this.

@rafal-r
Copy link

rafal-r commented Sep 24, 2024

@ohrrkan As mentioned in the documentation here:
https://supabase.com/docs/reference/javascript/select
(example for 'Query referenced tables through a join table')

We can infer types by doing this:

// To infer types, use the name of the table (in this case `users`) and
// the name of the foreign key constraint.
const { data, error } = await supabase
  .from('messages')
  .select(`
    content,
    from:users!messages_sender_id_fkey(name),
    to:users!messages_receiver_id_fkey(name)
  `)

Worked for me.

@yokowasis
Copy link

this works for me

  const { data, error } = await db
    .from("posts")
    .select(
      `
      id,
      content,
      user:users(
        id,
        full_name,
        handler,
        avatar
      )
      `
    )

user is the column name in posts
users is the name of foreign table.

@avallete
Copy link
Member

A fix has been released in supabase-js v2.46.0. I'm closing this issue, but feel free to reopen if you encounter any further errors.

@KouroshBhl
Copy link

I am using v2.46.1, and I have same issue here

@Gabriel-Volpini
Copy link

Same issue

@avallete
Copy link
Member

@KouroshBhl @Gabriel-Volpini

We had to revert the fix in 2.46.1 as we had some unexpected breaking changes due to the type rework.
However, we did released a new version as a "release candidate", and we are currently collecting feedback about it: https://github.com/orgs/supabase/discussions/30324

Please give 2.46.2-rc.3 a try, and don't hesitate to report back any remaining error with the debugging informations mentioned in the discussion. In the meantime I reopen this issue and will be closing it when this release candidate land on the main release channel (which should happen in December).

@avallete avallete reopened this Nov 25, 2024
@avallete
Copy link
Member

Happy to announce that we just released v2.47.8 that include the typing inference rework which should fix this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests