Limit the query to range on foreign table

I am having an issue with the limit the query to a range feature of the select function. My setup is I have a table called charge which has a foreign key of the charge group table, I would like to get the charge group and have pagination on the nested charge table. The limited documentation seems to imply I can do this with limit the query to a range setting but adding a foreign key seems to not change the behaviour of the query.



For testing there are no filters applied.
@Broberto any supabase wizardry we can use here?

I have managed this with some JS but If someone has a native solution that would be greatly appreciated.

  const { data, error } = await wwLib.wwPlugins.supabase.instance
    .from('charges_group')
    .select(`
      *,
      charge(*)
    `).range(0,5,{ referencedTable: 'charge' });
  if (error) {
    console.error('Error fetching data:', error);
    return null;
  }
  return data;
}
return fetchData()```

I contacted support a few days ago, in a collection, you can neither filter nor have limits on columns that come from a foreign key, maybe there could be an update in the future. The options are to do it with js like you did or to make a view

Thanks for the response.

the action I am doing is not a collection its a select, which you can filter on foreign keys. Broberto has a guide on how to do some of it. The select actions seem to be an attempt at implementing supabases select and they have given the option to specify the range on a foreign table as my previous images show but I am guessing my syntax is wrong somehow.

I think there is a bug. I just checked out and Supabase has said there is some deprecations with that settings, so that might be the issue. The JS SDK should work tho. @Alexis

1 Like

Hi @sam1 :wave:

I think there is a bug reported for a similar issue. Can you try toggling “Limit the number of Rows” before “Limit the query to a range”?

1 Like

Hi Dan,
That appears to be working thanks, I had to put in the foreign table and a count. The count in the limit number of rows seems to be overridden by the range in the limit the query to a range section. For example if I put a count of 1 but have a range that is 2 I will get 2 results.

Thanks again!