Best way to get foreign table's count? #669
-
Hi, Thanks for recent update (getting count feature) of library. It's super very cool. I have a question regarding this feature. I tried with the codes below. // tables: notes, comments
// comments table has a foreign key referencing notes table
let { data: notes, error } = await supabase
.from("notes")
.select(
`
id,
title,
description,
createdAt,
comments(
count
)`
)
// note is one element of notes array
const commentsCount = note.comments[0].count To access Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hey @imtaehyun, For now it's only possible to get the count through the array. Later on it'll be possible to "flatten" the embedded resource so you can get the count like: let { data: notes, error } = await supabase
.from("notes")
.select(
`
id,
title,
description,
createdAt,
commentsCount:comments(count)->count`
)
const commentsCount = note.commentsCount Pending enhancement tracked on: PostgREST/postgrest#1233 (comment) |
Beta Was this translation helpful? Give feedback.
Hey @imtaehyun,
For now it's only possible to get the count through the array.
Later on it'll be possible to "flatten" the embedded resource so you can get the count like:
Pending enhancement tracked on: PostgREST/postgrest#1233 (comment)