SupabaseS
Supabase4y ago
bent

I'm having trouble writing a query

In SQL, something like
select credit, link, collaborators.instagram, groups.id as group, theme from
groups join memberships on groups.id = memberships.group
join collaborators on collaborators.id = memberships.collaborator
where collab = 12

would be ok, and then I could use
map
and reduce to get it into this sort of structure:

[
  {
    "theme": "group 1s theme",
    "collaborators": [{"credit": "my name jeff", "link": "google.com", "instagram": "jeff"}, {"credit": "asdf", "link": "google.com", "instagram": "asdf"}]
  },
  {
    "theme": "group 2s theme",
    "collaborators": [{"credit": "ulfrick", "link": "google.com", "instagram": "stormcloak69"}]
  }
]


now, what's the best way to get there with supabase?
Is there even a way to get this done with only one request?

I can do this
  const { data, error } = await supabase.from<definitions["groups"]>("groups").select(`
  theme,
  collab (
    collaborators (
      credit
    )
  )`).eq('collab', id);

but then I get every person, even if they are not inside a group

and if I do
  const { data, error } = await supabase.from<definitions["groups"]>("groups").select(`
  theme,
  collaborators (
      credit
  )`).eq('collab', id);

collaborators will be an array in the result, but empty.
unknown.png
Was this page helpful?