© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•3y ago•
2 replies
Mr Void

SQL to supabase orm

How can I convert the following query to supabase's ORM ?

SELECT * FROM collections
INNER JOIN collection_share
ON collections.id = collection_share.collection_id
WHERE collection_share.shared_with = '< user id >'
SELECT * FROM collections
INNER JOIN collection_share
ON collections.id = collection_share.collection_id
WHERE collection_share.shared_with = '< user id >'


collection_share
collection_share
is linked to
collection
collection
by
collection_id
collection_id
column with
on_cascade_delete
on_cascade_delete



edit:

Got the following error when trying out the code below:
{
  "code": "22P02",
  "details": null,
  "hint": null,
  "message": "invalid input syntax for type uuid: \"collection_share.collection_id\""
}
{
  "code": "22P02",
  "details": null,
  "hint": null,
  "message": "invalid input syntax for type uuid: \"collection_share.collection_id\""
}


    await supabase
    .from('collections')
    .select("*, items (*), collection_share (shared_with, can_edit)")
    .filter("id", "eq", "collection_share.collection_id")
    .eq("collection_share.shared_with", sharedWithId)
    await supabase
    .from('collections')
    .select("*, items (*), collection_share (shared_with, can_edit)")
    .filter("id", "eq", "collection_share.collection_id")
    .eq("collection_share.shared_with", sharedWithId)


edit 2

Now i have tried the following:
    await supabase
    .from('collections')
    .select("*, items (*), collection_share (shared_with, can_edit)")
    .eq("collection_share.shared_with", sharedWithId)
    await supabase
    .from('collections')
    .select("*, items (*), collection_share (shared_with, can_edit)")
    .eq("collection_share.shared_with", sharedWithId)


However, this gives unexpected results. Returns all
collections
collections
instead of select few for
sharedWithId
sharedWithId
user

edit 3

After reading:
https://supabase.com/blog/postgrest-9#resource-embedding-with-inner-joins

I modified the code above using
!inner
!inner
:
    await supabase
    .from('collections')
    .select("*, items (*), collection_share!inner(shared_with, can_edit)")
    .eq("collection_share.shared_with", sharedWithId)
    await supabase
    .from('collections')
    .select("*, items (*), collection_share!inner(shared_with, can_edit)")
    .eq("collection_share.shared_with", sharedWithId)


Seems to be working now.

edit 4

I was wrong. It does not work. 😩
0 Results are fetched while there should have been 1 result.
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
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

SQL to Supabase query
SupabaseSSupabase / help-and-questions
3y ago
Compile SQL to Supabase DSL
SupabaseSSupabase / help-and-questions
6mo ago
Import from SQL to Supabase
SupabaseSSupabase / help-and-questions
4y ago
SQL queries in Supabase
SupabaseSSupabase / help-and-questions
4y ago