I have an app where `users` can subscribe to `page...
# off-topic
l
I have an app where
users
can subscribe to
pages
and submit
comments
on
pages
. I have a
users
table, a
pages
table, a
users_pages
table, and a
comments
table. I can currently pull a requested
page
, along with the
users
subscribed to it, with the following function. Is there anyway I can edit this to pull all of the
comments
for the requested page as well? Trying to fetch all of the
page
data in a single trip.
Copy code
javascript
 const { data, error } = await supabase
    .from('pages')
    .select(`*, users(id, email)`)
    .eq('slug', request.body.get('slug'))
s
If you have a reference key in the comments table to the pages id, then you should be able to pull it thru on the select too.
Copy code
js
 const { data, error } = await supabase
    .from('pages')
    .select(`*, users(id, email), comments(*)`)
    .eq('slug', request.body.get('slug'))
l
Thanks again for the help @User. When I try that, this is the error I'm getting:
Copy code
javascript
{
  message: 'More than one relationship was found for pages and users',
  hint: "By following the 'details' key, disambiguate the request by changing the url to /origin?select=relationship(*) or /origin?select=target!relationship(*)",
  details: [
    {
      relationship: 'public.users_pages[users_pages_page_id_fkey][users_pages_user_id_fkey]',
      cardinality: 'm2m',
      origin: 'public.pages',
      target: 'public.users'
    },
    {
      relationship: 'public.comments[comments_page_id_fkey][artifacts_user_id_fkey]',
      cardinality: 'm2m',
      origin: 'public.pages',
      target: 'public.users'
    }
  ]
}
Any thoughts on this @silentworks ? I tried following other threads on disambiguation, couldn't make any progress
s
So this is due to the relationship on teh comments table back to the users table, I've seen the fix posted for this before, let me try and find it and get back to you.
Sorry about the delay, I was a bit busy yesterday
l
No worries at all, thank you so much!! Really appreciate any insights on it
s
@User Could you retry the request? PostgREST 9 should be rolled out to all projects by now and it has an improved error message for these cases.
Though looking at the current error, I think you can fix it by doing:
Copy code
js
 const { data, error } = await supabase
    .from('pages')
    .select(`*, users!users_pages(id, email), comments(*)`)
    .eq('slug', request.body.get('slug'))
l
Thank you @User , this was the fix!!