© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•3y ago•
13 replies
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);
              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 🙂
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

multiple foreign keys in one table
SupabaseSSupabase / help-and-questions
4y ago
Many to Many link only working one level
SupabaseSSupabase / help-and-questions
4y ago
how to have an array of foreign keys (one to many relationship)?
SupabaseSSupabase / help-and-questions
4y ago
Foreign key relationship isn't one to one
SupabaseSSupabase / help-and-questions
3mo ago