SupabaseS
Supabase•2y ago
AC

Show entry only if at least one entry in foreign table One-to-Many relation

Hi,
selecting a foreign table with One-to-Many relationship with a condition like eq specific user id will still show the entity from the initial table even though the foreign table has an empty array. Is there a way to filter the entries by foreign table count not 0? I have tried many things but they lead to errors. This is my query
              const query = supabase.from('profiles')
                .select(`
                    user_id,
                    username,
                    accept_friend_requests,
                    friend_requests!friend_requests_addressee_id_fkey(
                        requester_id,
                        addressee_id
                    )
                `, { count: 'exact' })
                .ilike('username', `%${search}%`)
                .eq('friend_requests.requester_id', userId)
                .range(start, end);

If I could something say that friend_requests should be a right join, then it would return only the profile if any friend_requests are found. Thank you in regards 🙂
Was this page helpful?