supabase-js icon indicating copy to clipboard operation
supabase-js copied to clipboard

Unexpected type when querying referenced table with count

Open peperoli opened this issue 1 year ago • 2 comments

Bug report

Describe the bug

When querying a referenced table with count option like this:

const supabase = createClientComponentClient<Database>()

const { data } = supabase.from('concerts').select(`*, bands_count:j_concert_bands(count)`

count is returned correctly:

[
  {
    "id": 1,
    "bands_count": [
      {
        "count": 29
      }
    ]
  }
]

But when using the returned count value there's a type error:

data.forEach(item => {
  const count = item.bands_count[0].count
  // Property 'count' does not exist on type 'SelectQueryError<"Referencing missing column `count`">'.
}

Expected behavior

No error message because count does in fact exist.

System information

  • Version of supabase-js: 2.39.0
  • Version of Node.js: 18.19.0

peperoli avatar Jan 03 '24 09:01 peperoli

Im having same issue as well

salvinoto avatar Feb 13 '24 15:02 salvinoto

This issue is active in the postgrest-js repo: https://github.com/supabase/postgrest-js/issues/447

peperoli avatar Feb 13 '24 15:02 peperoli