© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•4y ago•
2 replies
config_wizard

Updating many2many relations with RPC call

Hi, from reading here, https://github.com/PostgREST/postgrest/issues/818
I have discovered that I need to create a function that will take the JSON of the object I want to update with all its relations as I can't do it with REST. I'm not quite sure what the function woud look like however to do this. I'm sending JSON in the form
{ //type customer:
    "id": 1,
    "description": "hello world",
    "friends": [
        {
            "id": 3,
            "name": "james bond"
        }
    ]
}
{ //type customer:
    "id": 1,
    "description": "hello world",
    "friends": [
        {
            "id": 3,
            "name": "james bond"
        }
    ]
}

I have a table holding all the top level objects, a table holding the friend and a table called
friends_connections
friends_connections
which holds the many2many relationships, i.e ID -> ID.
Using the javascript supabase library I am think I can do
rpc("update_contacts", jsonObj)
rpc("update_contacts", jsonObj)
but I'm not sure what I would put in the function? I think I could do it by literally updating each part one by one and perhaps pass the
friends
friends
as another argument rather than as a child, but I feel there is an atomic way I should be doing this where PSQL is clever enough to rollback the whole thing if something fails. A link of simple example of updating the
customer
customer
and the relations to
friends
friends
using the
friends_connections
friends_connections
table would be really helpful. Thank you!
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

RPC to duplicate a row with relations
SupabaseSSupabase / help-and-questions
4y ago
Timeout on RPC Call
SupabaseSSupabase / help-and-questions
3mo ago
Call RPC with mixed content (vchar, float)
SupabaseSSupabase / help-and-questions
4y ago
Updating DB: Edge functions or RPC?
SupabaseSSupabase / help-and-questions
4mo ago