Help with reverse addon in many-to-many relationship

Options

Hello,

I have two tables, Users and Groups, and Users has a table ref to Groups (Groups is not ref'd back to Users). This is a many to many relationship.

When running the Query All /Groups endpoint, I'm hoping to only returns groups in which the authenticated user is a member. Based on the Database - Part 3 video, it seems like using a reverse addon is the way to go here, but I'm a database newb and am really struggling.

The first thing I'm a littly shakey on is the fact that i'm not getting the virtual table that's an array of user.group_ids with which I could do an inner join. In the screenshot of the Database video, it looks like it's because he's querying jobs which have reference to location already. In my case, I don't. My groups do not have a reference to users.

So then I'm thinking, can I do an inner join without specifying an input. This doesn't error out but it returns all groups.

So then I'm wondering how I can limit the join to just group_ids of authenticated user. And, if I add a second join, I get that virtual table of user.group_ids that looks like the one in the video.

I'm sure I'm way over complicating this but have spent a few hours looking around in the community and doing good old trial and error and would appreciate any guidance.

Tagged:

Answers

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

    You might have an easier time stacking the queries in the function stack to move toward your goal. For example, start by "get record" from the user table for your particular user. Then, do a pull from groups where groups.id "IN" user_1.groups_id. After each query, try using stop-and-debug. This function terminates the function and lets you look at one variable. It can be super handy for finding out what is going on and how the machine thinks.

    This kind of stepwise data wrangling is often part of the "hardest 5%" that we tackle in our daily office hours and ask-for-help forums at State Change Pro.