Help required please, with what should be a simple data query

I’m struggling with what should be a simple query. I think I’m just not used to Bubble grammar/logic yet.

So I have three data types: User (email etc); Group (id, active?, etc); GroupMember (member, group, other data). The member field is a User object and group field is a Group object.

Now I want to display in a repeating group all users that are in the same active group (in GroupMember) as the current user.

So I have set the content type of my repeating group to GroupMember (I’ve also tried User). I am now trying to set my data source but I’m always getting an error.

As I see it, I need to:
a) Find the active group in GroupMember that my current user belongs to;
b) Find other GroupMember records with the same group
c) Return the list of User records for those GroupMember records

Below is a screenshot of my latest attempt:

Your don’t need the GroupMember table. Just create a “Member” field on the User table and make it a list of groups. Think of it as a nested array of groups.

1 Like

Hey @louisadekoya,

I think I can help you out. Add a field to your Group type that is a list of GroupMembers (you can call it “List of Group Members”) and when a new group member is created, add that record to the proper Group. Essentially, you’re creating a 2-way reference. You already have the Group attached to the GroupMember, but you’ll have more flexibility by having the Group data type contain its list of GroupMembers as well.

Once you do that, your RG’s source can just be “Current User’s Group’s List of Group Members” - which will obviously also include the Current User. To leave the current user out, add a :filter modifier where unique id <> current user’s unique id. <> means doesn’t equal.

Also, just a thought, depending on your needs, you may not even need a GroupMember type at all if they’re just Users. You’re kind of adding an extra step to reference the same people. But some Bubblers like to separate user types for various reasons.

Hope this helps!


Gaby | Coaching Bubble

1 Like

Thanks @Kfawcett, the thing is, I need to hold some data against each group member in relation to the group they are in. E.g. the role they play in the group. Otherwise, I would have done something similar to what you are suggesting, for example having a list of users on the group record, which is similar but perhaps the reverse of your suggestion.

1 Like

Yeah, so if they’re a member of different groups with a different role for each, having that separated is probably going to be easier to manage in the long run. But if they’ll only always be a member of 1 group, you can store all that role info with the User itself.

Hi @romanmg, thanks. Yes, over time, a user will belong to many groups, with a different role in each. I did wonder about a 2-way reference but the normalised relation database person in me was resisting the idea. I do see how it might make things easier though, so I will give it a go. Many thanks.

1 Like

Great. Here is one way you could do it the way you currently have it, though it just seems far more elaborate than it needs to be, but I get you :slight_smile:

Search for GroupMember’s Members with constraint: Group = Search for GroupMember’s Group with constraints: Member = Current User, Active = Yes

The problem that you’ll quickly run into here though is that there may be multiple active group’s where the current user is a member, so you’d have to then identify with that Group ID. Again, having the GroupMembers listed under Group will also make that search easier too. “Search for Group’s GroupMembers where ID=xyz”

Good luck!

@romanmg, you are a star. I didn’t even notice that it was possible to do a search within the constraint itself. This changes everything I think. I was about to go to bed (it’s 1am her) but I think I may be able to crack this now :grin:. I’ll report back either way. Thanks a lot.

1 Like

It works! @romanmg, a member can only be in one active group at any one time, so that’s perfectly fine. Thanks again - much appreciated. I will experiment with your earlier suggestion as well.

1 Like