Many-to-many Relations

Hi there. I am very new to Glide and have watched several videos online to get going. I am building an app to keep track of sports teams and results. So I have one table with all the players names in it, and one table with all the team names in it. The relationships need to be “many-to-many” so each player can be in more than 1 team, and each team obviously would have more that 1 player in it. I am not sure how to do this as all the videos I have watched show a “1-to-many” or “many-to-1” relation

hi mills, add relation columns in both tables and select “match multiple”

1 Like

You should choose to store this type of relation in text form in one table.

If you choose the teams table, have a column to store a comma-delimited lists of player IDs for each team. Split them into an array using the split text column, and relate that to the players table. In the players table, create a multiple relation from the rowID column to the array in the teams table.

If you choose the players table, have a column to store a comma-delimited lists of team IDs for each player. Split them into an array using the split text column, and relate that to the teams table. In the teams table, create a multiple relation from the rowID column to the array in the players table.

Is it a bad thing to have relation columns in both tables?

I think it depends on what he’s trying to do. If I need to display which teams a player belongs to, and which players belong to a team, then I would need relations in both tables.

The key point is the information should only be updated on one side.

1 Like

Thank you for the reply. I have found a few things that I am trying! Like I said, I’m very new to Glide so will figure it out

2 Likes

I’ve done this. How can I filter a view of my many-to-many? For example, I would like to click on a player and see a view of which teams they are in?

Thanks

(please avoid cross posting the same thing to multiple threads)

Welcome to Glide.

My approach to building changes all the time, but for the past few weeks I have decided to stop overthinking many-to-many relations. If there is one, I create a ThingsA↔︎ThingsB join table where I write row IDs of ThingsA and ThingsB, and that table is my relation. As soon as I create the table I create a single relation to the table of ThingsA and a single relation to the table of ThingsB, and back the other way.

I’m discovering aspects about join tables as I go along, and I’m sure I’m oblivious to many of their pitfalls, but the alternative is CSV values in cells and splitting them into arrays and then relating and that rigamarole. It works fine if there are few entities in the application, but it can get complicated quickly (at least to me). Personally I have trouble visualizing how data and tables relate in the first place, and join tables are making it slightly easier.

2 Likes