Many-to-Many Relationships

@Alfonso_Aguilar I think you are missing the Email Special Value when adding participants. It’s not saving with an email.

Sure! My fault. Should be fixed now. Thanks @Jeff_Hager!

1 Like

Hi @George_B :wave:

We seem to be facing a similar issue with the Many-to-Many relation feature, but unfortunately can’t seem to access your example app anymore:
https://many2many.glideapp.io

Here is a quick explanation of our issue:

The use case
We need to recommend specific selections of services to specific users, meaning:

  • 1 user = Many services
  • 1 service = Many users

The database
We have :

  • 1 spreadsheet with 1 row = 1 user = many services :white_check_mark:
  • 1 spreadsheet with 1 row = 1 service = many users :x: >> but no user will show up in the users relation column. Which means that we can’t filter the services that we will show to users.

Here is a short video explaining the issue:

We’ve been trying to figure this out, but nothing will do the trick and I feel like we might be missing something. Does someone know how to make this work?

Cheers :pray:

The first thing I notice is that you are comparing two unrelated columns. You are comparing a name to a user email. Those values will never match each other. A relation needs a common value that matches down to the letter.

Can you also show how your relation is set up in the Tes Service sheet? From what I’m understanding, you want the opposite of that relation in the Detail Services sheet?

It seems that that app somehow got unpublished. I republished it and made it copyable so you can take a look at it. https://many2many.glideapp.io/

Awesome thank you @George_B :pray:

@Jeff_Hager thank you for your reply, here is a video answering your questions:

Ok. It gets confusing sometimes because glide uses the same column icon for both relation columns and array columns. Your joined service columns in Tes Service is what we call an array column, because it’s an array of multiple values.

What you should be doing is changing your relation in the Detail Service sheet to link the Nom to the Service column in Tes Service. Again, you are trying to match a service name to an email address, which will never match because Service Name does not equal email address.

If your goal is to get an array of email addresses into the Detail Service sheet, then you just need to fix your relation to link name to service. This will link the row in the Details sheets to multiple ROWS in the Tes sheet. The you will add a Lookup column to pull the array of email addresses out of the the relation.

3 Likes

Thank you so much for your help!

We were able to make it work!

In our case, creating a separate “Attendees” (or in our case “Services-Users”) sheet, wasn’t possible as we don’t have a button that will trigger the creation of each row.
What did the trick was to add 2 columns in our “Detail services” sheet:

  • Email ID - Service relation
  • Lookup email id

Here is a quick explanation, just in case it might be useful for others :slight_smile: :

3 Likes

Hi george! Thanks for this app. It’s super cool. How did you create the Attendees sheet? I’m troubling creating mine. Specifically, I wanna have a similar table with every single relationship in each row (like participant, event, and participant-event combined that you have)

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

3 Likes

Yes, this a well known technique. :+1:

1 Like

I guess I’m new to the party – I couldn’t find it anywhere in the glide forums so I thought It’d be worth sharing here. What other well know techniques are the experts guarding for themselves? :sweat_smile:

1 Like

hehe…

Before multi-select was an option with the Choice component, we used to use a method called Trebuchet to achieve basically the same thing.

As to other techniques, I guess you learn as you find a need. Sooner or later you’ll probably find yourself looking for a helper table.

And of course there is all sorts of funky stuff you can do with JSON & JavaScript :slight_smile:

@NoCodeAndy recently asked for examples of Community threads that might be considered useful. Two that would be at the top of my list are Fun with Dates and Reset Multiple Rows at once. That second one can now be achieved with Call API, but it’s still an incredibly useful trick to have in your Glide Toolbox.

In fact, any posts by @Jeff_Hager are worth a read. His Calculator Challenge is a great example of stretching the boundaries with Glide.

And of course, you can’t go wrong with any of @Robert_Petitto’s tutorials. That’s where I got most of my early learning with Glide. Bob’s Miracle Method is one you absolutely need to know about.

5 Likes

Oh this is interesting reading.

I needed a many to many on my app and have it working really nicely with a third table.

I’m terrible at tinkering. Now trying to decide whether I leave it be or rip it apart for method! Does work well at the moment but maybe this is better???!! It’s a small app with only approx 50 users. My join table at most will have 250 rows so no big saving there.

Food for thought though

Thanks for posting!

Indeed this is beautiful and a great technique! Thanks for sharing -

But I don’t think I would be able to use it in my use case. I want to be able to update many relationships from either table.

The screenshot shows what I am trying to do (and have achieved with a 3rd junction table - just intrigued whether I can get it to work using your technique)

As the Choice component can only write to a field on the current table - there is no way of keeping it in sync - that I can see. Ideally, I guess, the choice component would be able to write to a related field (which doesn’t seem to be possible)

In a nutshell, my real world example is add a technician to many rooms OR assign a room to many technicians.

I’ve also published my attempt here - open access

The choice components in the Technicians (bottom) section don’t seem to do anything. Should they?

2 Likes

Thanks Darren - Still not sleeping?!

Well ideally yes - they would update the choice components in the top (rooms) section as I update the bottom ones so both tables are in sync.

But as I can only write to a column in the same table as the source - there is no way that I can see of sharing the selections of the choice component in the bottom table (if that makes sense)

1 Like

On a golfing vacation in Thailand, actually. But just taking a break from golfing for a few hours :slight_smile:

Kind of. For a use case like this, you might be better off using Collections rather than Choice components, and then configure the item click actions to manipulate arrays (add/remove as collection items are clicked). Try having a play with the following column types:

  • Multiple Files (can hold an array of anything)
  • Make Array (for adding items to an array)
  • Remove Element (for removing items from an array)
2 Likes

Ahh thanks Darren

I’ve got it working nicely already with a junction table so think I’ll stick with that. Was just intrigued to see whether I could achieve the same thing without that third table.

Enjoy your golf!