Many to many relationships

I’m struggling with many-to-many here. My goal is

  • have a list of members
  • have a list of possible events
  • members can choose which events they are going to
  • on the app show an event and who is attending that

I saw this post referencing 3 sheets Many-to-Many Relationships - #22 by Alfonso_Aguilar but the sample is not there anymore.

Something isn’t clicking for me even after watching all the videos on relationships in Glide.

1 Like

Hi @timheuer

I know you said you have watched videos, just checking that you have seen this one?

And read this

Yes unfortunately those are not helping me…I’m clearly missing something in my brain.

In a normal database I’d have 3 tables: members, events, memberevents – I’m just not seeing how 3 sheets then map using this relational column concept and still show me the values i want

Hi @timheuer.

It was a long time ago and some current features were not available then… Here is a link to the sample app: https://many2many-norep.glideapp.io.

Take a look to the data tables in the app. You will find 3 tables:

  1. Events table: you list of possible events.
  2. Participants table: your list of members.
  3. Attendees table: your list of “memberevents". When a member chooses to go to an event, you create a row in this table.

Instead of creating a "many-to-many” relation between Events and Participants, you should create 2 “one-to-many” relations:

  1. Events(1)-to-Attendees(many): one event can have relate to many member-event pairs (or have many participants).
  2. Participants(1)-to-Attendees(many): one member can relate to many member-event pairs (or "be an attendee” to many events).

When a member chooses to attend an event, you just need to create a new member-event pair in the Attendees table. You can traverse the relations to grab data from the related tables using LookUp columns.

Hope this helps.

3 Likes

Thanks @Alfonso_Aguilar this is helpful to look at – I’ve made more progress. Now trying to display the right things on the form is hard:

Done - I want a Member screen that shows the name of all events they are getting
Done - A list of events
Not figured out - Look at the event details and show a list of names that are registered (not the unique key) and allow link to the details of that member

You can use a LookUp column.

Notice that to reach the Participants table from the Events table you have to traverse 2 relations: Events-to-Attendees and Attendees-to-Participants. For your reference,I have added a new LookUp column to the Events table in the sample app. You may need to get an updated copy of the app (link: https://many2many-norep.glideapp.io/).

Please, have a look at it and try to do the same in your app:

Step 1. In your Events data table, create a LookUp column and configure it to reach into the Participants table through the necessary relations (Events-to-Attendees > Attendees-to-Participants).
Step 2. In your Events layout, select the LookUp column created in Step 1 as the source for the values in the list of attendees.
Step 3. You should now see and be able to use Participants data to populate list entries.
Step 4. By default, tapping on any entry in the list will show the Participant details (you can change this by selecting a different action in the list Features tab).

Good luck!

2 Likes

This worked for me… but whoo I wasn’t going to come up with that for myself.
I had exactly the problem of two hops to get past the linking table, I didn’t think of doing the hops in the data tables :grinning:

Hey All,

After a little experimentation I figured out a method for a natively supported many-to-many relation without using a linking table.

There is a calculated column type called “Split Text” that makes the magic happen!

Here’s my methodology:

  1. Create a choice UX element on table A which allows you to select multiple items from table B storing those table B IDs as comma separated text on table A.
  2. Create a “Split Text” column on table A which reads your table B IDs and splits them into an array of multiple text objects each with a relevant table B ID
  3. Create a relation between table A and table B linking on the split text column
  4. When displaying objects from the related table (A->B OR B->A) use a “contained in” or “contains” filter to check for all not just one object.

Bonus) If you’d like to display this list of related objects in context, create a “Joined List” object to concatenate the relevant text into a single text field and display it as a single field.

Honestly It’s beautiful. Thank you Glide team for the split text column type!
-AVF

1 Like

If you have relations already, why do you need to use contain though?

Here’s a use case question, what happens in the case where you have teams with members with each member have different roles (ie. admin, manager, etc), how does that work?

In a normal database, you would create teams, members, team_members so it sounds like that would be different in Glide, is that correct?

Are you looking for something related to relations, or are you actually looking for Roles?