Adalo | many-to-many relationships in Xano

Options
GeneralJWS
GeneralJWS Member

I'm trying to create a relationship between my Users and Posts. Right now, whenever I create a post it does not get assigned to a user. I would like to know how to make it to where I a user can create a post and that post belong to that user. Can someone help with this? This would help be tremendously.

Thanks!

Answers

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options

    I think you're looking for a one-to-many relationship: a single user goes with multiple posts, but a given post only goes with one user. That's much easier to manage. You can create a field in the posts table called “user_id” (or “owner_id” or what have you) that is a table reference to your users table. Then, as part of the API endpoint (or what have you) that runs “add record”, you add the current user ID (probably from auth:id) into that field. Voila, data connection.

    if your data relationships are more complex, please share! Maybe I or others can help further.