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

`order` by foreign table not working.

Open DanMossa opened this issue 2 years ago • 2 comments

Describe the bug I'm trying to recreate the following query:

SELECT u.*
FROM users u
         JOIN likes l ON u.user_id = l.to_user_id
WHERE l.from_user_id = '148b5f51-82e2-4482-80e1-aec6e547d68c'
ORDER BY l.create_time DESC

When using order, to try and order the results by likes.create_time the results are not ordered by create_time.

It doesn't even seem to be ordered by users.create_time I actually have no idea what the ordering is lol.

To Reproduce

      final List<Map<String, dynamic>> res = await _supabase
          .from(constants.Table.users.name)
          .select('*, likes!to_user_id!inner(*)')
          .eq("likes.from_user_id", userId)
          .order('create_time', ascending: false, foreignTable: 'likes');

This is the url that's called from that query

https://khzlfnfbps.supabase.co/rest/v1/users?select=%2A%2Clikes%21to_user_id%21inner%28%2A%29&likes.from_user_id=eq.148b5f51-82e2-4482-80e1-aec6e547d68c&likes.order=create_time.desc.nullslast

Expected behavior I expect the rows I get from users to be ordered by the joined table, likes.create_time in descending order.

Additional context I found this https://github.com/supabase/postgrest-js/issues/198

DanMossa avatar Mar 12 '23 21:03 DanMossa

@DanMossa I just discovered this issue as well, is it only when ordering by a foreignTable that you experience this?

taylorjdawson avatar Mar 25 '23 18:03 taylorjdawson

@DanMossa I just created a view and that is a good workaround for now. Have the foreign key table sort within the view

taylorjdawson avatar Mar 25 '23 19:03 taylorjdawson